Flutter application crashes at startup on iPhone - ios

I wrote a basic calculator app with flutter and installed it on my iphone with Xcode.
I builded the app and trusted the developer in the iPhone settings. But when I want to open the app it crashes after about 2 seconds of my background screen in blurry. I don't know what is wrong the app runs on the simulator. I don't know if the code is to bad written or if I missed some configuration steps. Has somebody experience with that...
Thank you for your help.
Device Log/ Crash:
{
"crashReporterKey" : "771e2f68485128ac7de5b4f2d3a557289be32a15",
"kernel" : "Darwin Kernel Version 20.0.0: Fri Aug 28 23:07:00 PDT 2020; root:xnu-7195.0.46~9\/RELEASE_ARM64_T8020",
"product" : "iPhone11,2",
"incident" : "E2C76AF9-8284-47F9-962E-FE6DB1D9AD19",
"date" : "2020-09-28 21:24:44.54 +0200",
"build" : "iPhone OS 14.0.1 (18A393)",
"timeDelta" : 6,
"memoryStatus" : {
"compressorSize" : 29314,
"compressions" : 1810481,
"decompressions" : 1202975,
"zoneMapCap" : 1454407680,
"largestZone" : "APFS_4K_OBJS",
"largestZoneSize" : 35880960,
"pageSize" : 16384,
"uncompressed" : 79755,
"zoneMapSize" : 162873344,
"memoryPages" : {
"active" : 75993,
"throttled" : 0,
Flutter Code
import 'package:flutter/material.dart';
void main() {
runApp(Calculator());
}
class Calculator extends StatefulWidget {
#override
_CalculatorState createState() => _CalculatorState();
}
class _CalculatorState extends State<Calculator> {
String _num1 = "";
String _operator = "";
String _num2 = "";
String _show = "";
bool _set_show_to_none = false;
bool _isNum2 = false;
void press_0_button_num1() {
setState(() {
_num1 += "0";
_show += "0";
});
}
void press_1_button_num1() {
setState(() {
_num1 += "1";
_show += "1";
});
}
void press_2_button_num1() {
setState(() {
_num1 += "2";
_show += "2";
});
}
void press_3_button_num1() {
setState(() {
_num1 += "3";
_show += "3";
});
}
void press_4_button_num1() {
setState(() {
_num1 += "4";
_show += "4";
});
}
void press_5_button_num1() {
setState(() {
_num1 += "5";
_show += "5";
});
}
void press_6_button_num1() {
setState(() {
_num1 += "6";
_show += "6";
});
}
void press_7_button_num1() {
setState(() {
_num1 += "7";
_show += "7";
});
}
void press_8_button_num1() {
setState(() {
_num1 += "8";
_show += "8";
});
}
void press_9_button_num1() {
setState(() {
_num1 += "9";
_show += "9";
});
}
void press_0_button_num2() {
setState(() {
if (_set_show_to_none){
_show = "";}
_num2 += "0";
_show += "0";
_set_show_to_none = false;
});
}
void press_1_button_num2() {
setState(() {
if (_set_show_to_none){
_show = "";}
_num2 += "1";
_show += "1";
_set_show_to_none = false;
});
}
void press_2_button_num2() {
setState(() {
if (_set_show_to_none){
_show = "";}
_num2 += "2";
_show += "2";
_set_show_to_none = false;
});
}
void press_3_button_num2() {
setState(() {
if (_set_show_to_none){
_show = "";}
_num2 += "3";
_show += "3";
_set_show_to_none = false;
});
}
void press_4_button_num2() {
setState(() {
if (_set_show_to_none){
_show = "";}
_num2 += "4";
_show += "4";
_set_show_to_none = false;
});
}
void press_5_button_num2() {
setState(() {
if (_set_show_to_none){
_show = "";}
_num2 += "5";
_show += "5";
_set_show_to_none = false;
});
}
void press_6_button_num2() {
setState(() {
if (_set_show_to_none){
_show = "";}
_num2 += "6";
_show += "6";
_set_show_to_none = false;
});
}
void press_7_button_num2() {
setState(() {
if (_set_show_to_none){
_show = "";}
_num2 += "7";
_show += "7";
_set_show_to_none = false;
});
}
void press_8_button_num2() {
setState(() {
if (_set_show_to_none){
_show = "";}
_num2 += "8";
_show += "8";
_set_show_to_none = false;
});
}
void press_9_button_num2() {
setState(() {
if (_set_show_to_none){
_show = "";}
_num2 += "9";
_show += "9";
_set_show_to_none = false;
});
}
void press_plus_button() {
setState(() {
_operator = "+";
_show = "+";
_set_show_to_none = true;
_isNum2 = true;
});
}
void press_minus_button() {
setState(() {
_operator = "-";
_show = "-";
_set_show_to_none = true;
_isNum2 = true;
});
}
void press_multiple_button() {
setState(() {
_operator = "*";
_show = "*";
_set_show_to_none = true;
_isNum2 = true;
});
}
void press_divided_button() {
setState(() {
_operator = "/";
_show = "/";
_set_show_to_none = true;
_isNum2 = true;
});
}
void press_ac_button() {
setState(() {
_num1 = "";
_operator = "";
_num2 = "";
_show = "";
_set_show_to_none = false;
_isNum2 = false;
});
}
void calculate() {
setState(() {
int num1int = int.tryParse(_num1);
int num2int = int.tryParse(_num2);
double num1do = num1int.toDouble();
double num2do = num2int.toDouble();
double result = 0;
if (_operator == "+") {
result = num1do + num2do;
}
else if (_operator == "-") {
result = num1do - num2do;
}
else if (_operator == "*") {
result = num1do * num2do;
}
else if (_operator == "/") {
result = num1do / num2do;
}
RegExp regex = RegExp(r"([.]*0)(?!.*\d)");
String result_output = result.toString().replaceAll(RegExp(r"([.]*0)(?!.*\d)"), "");
_show = result_output;
});
}
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Column(
children: <Widget>[
SizedBox(
height: 98,
),
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: Text(_show,
textAlign: TextAlign.right,
style: TextStyle(fontSize: 130)),
),
),
Row(
children: [
Container(
padding: const EdgeInsets.all(10.0),
child: SizedBox(
height: 70,
width: 150,
child: FloatingActionButton.extended(
elevation: 0.2,
onPressed: () {
press_ac_button();
},
label: Text("AC"),
isExtended: true,
),
),
),
],
),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {
if (_isNum2) {
press_1_button_num2();
} else {
press_1_button_num1();
}
},
child: Text("1"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {
if (_isNum2) {
press_2_button_num2();
} else {
press_2_button_num1();
}
},
child: Text("2"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {
if (_isNum2) {
press_3_button_num2();
} else {
press_3_button_num1();
}
},
child: Text("3"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {
press_plus_button();
},
child: Text("+"),
),
),
],
),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {
if (_isNum2) {
press_4_button_num2();
} else {
press_4_button_num1();
}
},
child: Text("4"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {
if (_isNum2) {
press_5_button_num2();
} else {
press_5_button_num2();
}
},
child: Text("5"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {
if (_isNum2) {
press_6_button_num2();
} else {
press_6_button_num1();
}
},
child: Text("6"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {
press_minus_button();
},
child: Text("-"),
),
),
],
),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {
if (_isNum2) {
press_7_button_num2();
} else {
press_7_button_num1();
}
},
child: Text("7"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {
if (_isNum2) {
press_8_button_num2();
} else {
press_8_button_num1();
}
},
child: Text("8"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {
if (_isNum2) {
press_9_button_num2();
} else {
press_9_button_num1();
}
},
child: Text("9"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {
press_multiple_button();
},
child: Text("*"),
),
),
],
),
SizedBox(
height: 3,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
height: 90,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {
if (_isNum2) {
press_0_button_num2();
} else {
press_0_button_num1();
}
},
child: Text("0"),
isExtended: true,
),
),
SizedBox(
height: 75,
width: 180,//290
child: FloatingActionButton.extended(
elevation: 0.2,
onPressed: () {
calculate();
},
label: Text("="),
isExtended: true,
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {
press_divided_button();
},
child: Text("/"),
),
)
],
),
SizedBox(height: 47.5),
],
),
),
);
}
}
I have two errors in Xcode:

Go into xcode and change your Bundle Identifier to something like this using your own website name.
com.mywebsitename.calculator

Related

How to Center Align vertically a TextField Content in Jetpack Compose?

I have a TextField but it's value can't be seen completely and almost Half of it's content goes below the Field.
what should I add to this TextField?
Here is the code:
val text = remember { mutableStateOf("") }
TextField(
modifier = Modifier
.height(60.dp)
.width(230.dp)
.padding(0.dp),
value = text.value,
textStyle = TextStyle(
fontSize = 25.sp,
),
onValueChange = { nextText ->
text.value = nextText
},
label = {
Text(
modifier = Modifier.padding(10.dp),
text = "search",
textAlign = TextAlign.Start,
fontSize = 13.sp
)
},
singleLine = true,
trailingIcon = {
IconButton(onClick = {
}) {
Icon(
imageVector = Icons.Filled.Search,
contentDescription = "Search Button",
modifier = Modifier.size(25.dp)
)
}
}, keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Text,
imeAction = ImeAction.Search
),
keyboardActions = KeyboardActions(onSearch = {
})
)
And it's how it looks like:

Jetpack Compose permissions bug

Trying to request READ_EXTERNAL_STORAGE to select an image from the users gallery permission but the permissions launcher automatically hits the denied branch of the if statement without even attempting to open the permission dialog. This code works fine on Android 12 and below, but not on Android 13. Does anyone know what could be causing this issue?
#Composable
fun CreateComposable(
navigateToStorePreview: (String) -> Unit
) {
val viewModel = hiltViewModel<CreateViewModel>()
val state by viewModel.state.collectAsState()
LaunchedEffect(key1 = viewModel.effects) {
viewModel.effects.collect { effect ->
when (effect) {
}
}
}
CreateScreen(state = state, eventHandler = viewModel::postEvent)
}
#OptIn(ExperimentalCoilApi::class)
#Composable
internal fun CreateScreen(
state: CreateState,
eventHandler: (CreateEvent) -> Unit
) {
val context = LocalContext.current
val galleryLauncher = rememberLauncherForActivityResult(
ActivityResultContracts.GetContent()
) { uri: Uri? ->
uri?.let { eventHandler(CreateEvent.SetUriFromCamera(uri = uri)) }
}
val permissionLauncher = rememberLauncherForActivityResult(
ActivityResultContracts.RequestPermission()
) { isGranted: Boolean ->
if (isGranted) {
galleryLauncher.launch("image/*")
} else {
showToast(context, context.getString(R.string.permissions_denied_resolution))
}
}
Column(
modifier = Modifier
.padding(horizontal = 16.dp)
.padding(bottom = 24.dp)
.fillMaxSize()
.verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.SpaceBetween,
horizontalAlignment = Alignment.CenterHorizontally
) {
Spacer(modifier = Modifier.height(1.dp))
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
OutlinedTextField(
modifier = Modifier
.widthIn(200.dp),
value = state.flashCardName,
onValueChange = {
eventHandler(CreateEvent.FlashCardNameUpdated(input = it))
},
colors = TextFieldDefaults.outlinedTextFieldColors(
backgroundColor = Color.Transparent,
focusedBorderColor = Color.Transparent,
unfocusedBorderColor = Color.Transparent,
cursorColor = WildBlueYonder
),
label = {
Text(
text = stringResource(id = R.string.enter_flash_card_name),
color = Color.LightGray
)
},
leadingIcon = {
Image(
painter = painterResource(id = R.drawable.add),
contentDescription = null,
colorFilter = ColorFilter.tint(WildBlueYonder)
)
},
textStyle = TextStyle(
color = WildBlueYonder,
fontFamily = Baloo2,
fontSize = 16.sp
),
shape = RoundedCornerShape(16.dp),
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Password
)
)
if (state.imageUri.isEmpty()) {
Box(
modifier = Modifier
.padding(horizontal = 16.dp)
.height(300.dp)
.width(200.dp)
.clip(RoundedCornerShape(16.dp))
.border(4.dp, WildBlueYonder, RoundedCornerShape(16.dp))
.clickable {
when (ContextCompat.checkSelfPermission(
context,
Manifest.permission.READ_EXTERNAL_STORAGE
)) {
PackageManager.PERMISSION_GRANTED -> {
galleryLauncher.launch("image/*")
}
else -> {
permissionLauncher.launch(Manifest.permission.READ_EXTERNAL_STORAGE)
}
}
}
) {
Image(
modifier = Modifier.align(Alignment.Center),
painter = painterResource(id = R.drawable.add),
contentDescription = null,
colorFilter = ColorFilter.tint(TeaGreen)
)
}
} else {
Image(
modifier = Modifier
.height(300.dp)
.width(200.dp),
painter = rememberImagePainter(data = state.imageUri.toUri()),
contentDescription = null
)
}
}
BouncyButton(
modifier = Modifier.fillMaxWidth(),
enabled = true,
text = stringResource(id = R.string.bottom_bar_create),
onClick = {
eventHandler(CreateEvent.CreateClicked)
}
)
}
}

Snackbar is never dismissed (Jetpack Compose SnackbarHostState)

Description
Calling showSnackbar on SnackbarHostState and passing a duration argument does not dismiss the Snackbar. The coroutine appears to suspend for infinity.
Steps to Reproduce:
val snackbarHostState = remember{mutableStateOf(SnackbarHostState())}
Column {
Button(
onClick = {
lifecycleScope.launch {
val time = System.currentTimeMillis()
Log.d(TAG, "showing snackbar")
snackbarHostState.value.showSnackbar(
message = "Hey look a snackbar",
actionLabel = "Hide",
duration = SnackbarDuration.Short
)
Log.d(TAG, "done ${System.currentTimeMillis()-time}") // <-- Never called
}
}
) {
Text("Show snackbar")
}
snackbarHostState.value.currentSnackbarData?.let { snackbarData ->
ConstraintLayout(
modifier = Modifier.fillMaxSize()
) {
val snackbar = createRef()
Snackbar(
modifier = Modifier.constrainAs(snackbar) {
bottom.linkTo(parent.bottom)
start.linkTo(parent.start)
end.linkTo(parent.end)
},
snackbarData = snackbarData,
)
}
}
}
I guess you need to wrap the Snackbar in a SnackbarHost because this works as expected.
val snackbarHostState = remember{mutableStateOf(SnackbarHostState())}
Column {
Button(
onClick = {
lifecycleScope.launch {
val time = System.currentTimeMillis()
Log.d(TAG, "showing snackbar")
snackbarHostState.value.showSnackbar(
message = "Hey look a snackbar",
actionLabel = "Hide",
duration = SnackbarDuration.Short
)
Log.d(TAG, "done ${System.currentTimeMillis()-time}") // <-- Never called
}
}
) {
Text("Show snackbar")
}
ConstraintLayout(
modifier = Modifier.fillMaxSize()
) {
val snackbar = createRef()
SnackbarHost(
modifier = Modifier.constrainAs(snackbar) {
bottom.linkTo(parent.bottom)
start.linkTo(parent.start)
end.linkTo(parent.end)
},
hostState = snackbarHostState.value,
snackbar = {
Snackbar(
action = {
TextButton(onClick = {
snackbarHostState.value.currentSnackbarData?.dismiss()
}) {
Text(
text = "Hide",
)
}
}
) {
Text("hey look a snackbar")
}
}
)
}
}

Adding headers to OutlineGroup / DisclosureGroup

I'm using SwiftUI 2.0, and I need a way to add a header to an OutlineGroup or DisclosureGroup, similar to headers in List sections. Is there a way to do this?
You can use separate Sections to create the headers (and, optionally, footers).
import SwiftUI
struct Node : Identifiable {
let id = UUID()
let name: String
let children: [Node]?
}
struct SectionedOutlineView: View {
var body: some View {
List(selection: $selection) {
Section(header: Label("Nodes 1", systemImage: "sparkle")) {
OutlineGroup(nodes1, children: \.children) { node in
Label(node.name, systemImage: "shield")
}
}
Section(header: Label("Nodes 2", systemImage: "rosette")) {
OutlineGroup(nodes2, children: \.children) { node in
Label(node.name, systemImage: "folder")
}
}
}
.listStyle(SidebarListStyle())
}
#State var nodes1 = [
Node(name: "Layer 1", children: [
Node(name: "Layer 1-1", children: [
Node(name: "Layer 1-1-1", children: nil),
Node(name: "Layer 1-1-2", children: nil),
]),
Node(name: "Layer 1-2", children: [
Node(name: "Layer 1-2-1", children: nil),
Node(name: "Layer 1-2-2", children: nil),
Node(name: "Layer 1-2-3", children: nil),
]),
Node(name: "Layer 1-3", children: nil),
]),
Node(name: "Layer 2", children: [
Node(name: "Layer 2-1", children: [
]),
Node(name: "Layer 2-2", children: [
]),
Node(name: "Layer 2-3", children: [
]),
])
]
#State var nodes2 = [
Node(name: "Layer 1", children: [
Node(name: "Layer 1-1", children: [
Node(name: "Layer 1-1-1", children: nil),
Node(name: "Layer 1-1-2", children: nil),
]),
Node(name: "Layer 1-2", children: [
Node(name: "Layer 1-2-1", children: nil),
Node(name: "Layer 1-2-2", children: nil),
Node(name: "Layer 1-2-3", children: nil),
]),
Node(name: "Layer 1-3", children: [
]),
]),
Node(name: "Layer 2", children: [
Node(name: "Layer 2-1", children: [
]),
Node(name: "Layer 2-2", children: [
Node(name: "Layer 2-2-1", children: nil),
Node(name: "Layer 2-2-2", children: nil),
Node(name: "Layer 2-2-3", children: nil),
]),
Node(name: "Layer 2-3", children: [
]),
])
]
#State var selection = Set<Node.ID>()
}
import SwiftUI
struct NodeOutlineGroup<Node>: View where Node: Hashable, Node: Identifiable, Node: CustomStringConvertible{
let node: Node
let childKeyPath: KeyPath<Node, [Node]?>
let headerKeyPath: KeyPath<Node, String?>?
#State var isExpanded: Bool = true
var body: some View {
if node[keyPath: childKeyPath] != nil {
DisclosureGroup(
isExpanded: $isExpanded,
content: {
if isExpanded {
ForEach(node[keyPath: childKeyPath]!) { childNode in
NodeOutlineGroup(node: childNode,
childKeyPath: childKeyPath,
headerKeyPath: headerKeyPath,
isExpanded: isExpanded)
}
}
},
label: {
section
})
} else {
section
}
}
var section: some View {
VStack(alignment: .leading) {
if let kp = headerKeyPath, let header = node[keyPath: kp] {
Section(header:
HStack {
Text(header)
Spacer()
}
.background(Color.secondary.opacity(0.3))
) {
Text(node.description)
}
} else {
Text(node.description)
}
}
}
}
struct ContentView: View {
var body: some View {
List {
NodeOutlineGroup(node: data, childKeyPath: \.children, headerKeyPath: \.header, isExpanded: true)
}
.listStyle(InsetGroupedListStyle())
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
// Sample data
struct FileItem: Hashable, Identifiable, CustomStringConvertible {
var id: Self { self }
var name: String
var header: String?
var children: [FileItem]? = nil
var description: String {
switch children {
case nil:
return "📄 \(name)"
case .some(let children):
return children.isEmpty ? "📂 \(name)" : "📁 \(name)"
}
}
}
let data =
FileItem(name: "users", children:
[FileItem(name: "user1234", children:
[FileItem(name: "Photos", header: "Header 1", children:
[FileItem(name: "photo001.jpg", header: "Header 2"),
FileItem(name: "photo002.jpg")]),
FileItem(name: "Movies", children:
[FileItem(name: "movie001.mp4")]),
FileItem(name: "Documents", children: [])
]),
FileItem(name: "newuser", children:
[FileItem(name: "Documents", children: [])
])
])

Styling features based on attribute values

How does one style features based on attributes/properties? Currently I am doing the following:
olLayer = new ol.layer.Vector( {
source: new ol.source.Vector( {
features: featureArray
} ),
style: ( function() {
var styleR3 = new ol.style.Style( {
image: new ol.style.Circle( {
radius: 10,
fill: new ol.style.Fill( {
color: 'blue'
} )
} )
} );
var styleCatchAll = new ol.style.Style( {
image: new ol.style.Circle( {
radius: 5,
fill: new ol.style.Fill( {
color: 'red'
} )
} )
} );
return function( feature, resolution ) {
if ( feature.attributes[ "Rank" ] === "3" ) {
return styleR3;
} else {
return styleCatchAll;
}
};
}() )
} );
The select features does work but the styleR3 does not get applied.
Here it is ... http://jsfiddle.net/jonataswalker/g3s96auc/
The style function requires an array on return, and you are using a self execution function, I don't know if this works, anyway, the style function became:
style: function(feature, resolution){
var styleR3 = new ol.style.Style( {
image: new ol.style.Circle( {
radius: 10,
fill: new ol.style.Fill( {
color: 'blue'
} )
} )
} );
var styleCatchAll = new ol.style.Style( {
image: new ol.style.Circle( {
radius: 5,
fill: new ol.style.Fill( {
color: 'red'
} )
} )
} );
if ( feature.get('rank') == 3) {
return [styleR3];
} else {
return [styleCatchAll];
}
}

Resources