Tapping Flutter Textfield Crashes the app - android

here's a video which shows my problem.
https://drive.google.com/file/d/1YTnu1amCYhN9CGLygAyag-LhYMn3BDiO/view?usp=sharing
Thing is, I'm developing an app in flutter and have been debugging it for several months already in a real hardware (my own phone with android 11). Suddenly, today I have experienced this error. When I tap on a textfield or textformfield, the app crushes and restarts automatically. I've researched a couple forums which suggest:
But it doesn't work for me.
I've already been several hours trying to figure this out, rebooting my pc, my phone, trying an emulator, a friend's phone instead of mine, changing the properties of the textfields... But nothing seems to work. I've read that this problem happens randomly at some android 11 devices, but have seen no solution to it (I don't even know if there exists one).
About my code, it's as simple as this:
Flexible(
child: FractionallySizedBox(
widthFactor: 0.75,
heightFactor: 0.75,
alignment: Alignment.centerLeft,
child: TextFormField(
decoration: InputDecoration(
icon: Icon(Icons.person),
fillColor: Colors.white.withOpacity(0.80),
filled: true,
),
onChanged: (String v) => nombre = v,
textInputAction: TextInputAction.go,
),
),
),
My pubspec dependencies are:
firebase_core: ^1.17.1
firebase_auth: ^3.3.19
firebase_database: ^9.0.15
firebase_messaging: ^11.4.1
firebase_storage: ^10.2.17
event: ^2.0.5
mutex: ^3.0.0
chat_bubbles: ^1.3.0
clipboard: ^0.1.3
image_picker: ^0.8.5+3
shared_preferences: ^2.0.15
path_provider: ^2.0.11
xdg_directories: ^0.2.0
flutter_tts: ^3.4.0
google_speech: ^2.1.1
speech_to_text: ^5.6.0
record: ^4.1.1
gcloud: ^0.8.5
flutter_local_notifications: ^9.6.0
http: ^0.13.4
crypto: ^3.0.2
semaphore: ^0.2.1
audioplayers: ^1.0.0
spring_button: ^2.0.0
google_fonts: ^3.0.1
flutter_app_name: ^0.1.1
As I said, it has delivered no problems for the last months.
If anyone has an idea that may make it work again, I would be very grateful. And if want more data of my project, just ask for it. Thank you very much in advance.

Three weeks since this problem appeared, I have at last discovered where the error was all along. It seems I had a window in the Navigator pile that was a Stateless Widget instead of a Stateful Widget, and when that happens, every time a reload happens (hot reload, textfield tapping, launching the keyboard, etc), provokes that the application restarts. It seems logical, actually, but I didn't think about that window at all, so I just popped it from the Navigator as soon as I finished with it and everything went just fine.

Related

Flutter launcher_icon and native_splash android problem

I am beginner in flutter, and I started learning from the very beginning of creating the application and immediately encountered a problem that I cannot solve only on android. When i create packages launcher_icon and native_splash, on ios everything works as it should, but on android at the splash screen all the time it gives me only the application icon and not default splash screen as in ios.
how could i fix it to work on android?
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
flutter_launcher_icons: ^0.10.0
flutter_native_splash: ^2.2.7
flutter_icons:
android: true
ios: true
image_path: "assets/icon_anny.png"
min_sdk_android: 21
flutter_native_splash:
color: "#fafafa"
image: assets/splash_screen.png
color_dark: "#000000"
image_dark: assets/splash_screen_dark.png
android: true
ios: true
android_gravity: fill
ios_content_mode: scaleAspectFill
I managed to solve the problem, Android 12 has a different way of showing the splash screen. It is also necessary to open a new one flutter_native_splash.yaml and there are all the instructions and it works perfectly.
You should run a command line after adding parameters to pubspec.yaml:
flutter pub run flutter_native_splash:create
I just fixed this problem today go in your project and create a flutter_native_splash.yaml and follow the instructions on https://pub.dev/packages/flutter_native_splash.

Flutter Error: No named parameter with the name 'displayLarge'

I am working on an app, I posted last update on git 2 days ago and haven't touched the code since. Now, I opened android studio and it was giving me this error when I tried to run it... I tried deleting repository from my computer and then cloning it again but it didn't work. I have also tried searching for similar problems, and found out there was a similar problem with speed-dial package and one comment said something about broken package versions. Anyways, this is the error I am getting after I try running my app:
These are first few lines of the error it's giving me, but there is more than a thousand lines following these.
I also tried running flutter doctor and it gave me the following:
google_fonts: ^2.3.1 has also solved the problems left in google_fonts: 2.3.0
Well! This issue will be raised in all projects using the google_fonts with a caret sign (^).
The caret sign (^) is used for pub dependencies in Dart to indicate a range of version numbers that are allowed. Specifically, any version from the specified version up to (but not including) the next non-breaking version is ok.
So google_fonts: ^2.2.0 is the same as '>=2.2.0 <3.0.0', It's shorthand for the longer form. The ^ is saying, I want to automatically use the most up-to-date package from Pub as long as that update won't break anything in my app. The google_fonts: 2.3.0 has some issues with this as of now.
Solution Steps :
Remove (^) from your current google_fonts. max can be set as google_fonts: 2.2.0.
To make sure, this does not conflict with any other dependency, for once do 'pub get'.
Try to invalidate caches and restart. This should clean error, else do flutter clean to remove old updated google_fonts and pub get.
Done! You are good to go. Happy Codding!!!
Please follow the below steps to solve the issue.
Open pubspec.yaml file.
Change google_fonts: ^2.2.0 to google_fonts: 2.2.0
Save.
Well, I don't know if you have tried this, but this problem is described here: issue 219
In summary, you have to use google_fonts v2.3 for Flutter v2.1 or greater.
set the package version to google_fonts: 2.2.0 and it should work properly
as they said, just remove the ^ from the google fonts on the dependencies on the pubspec.yaml
(google_fonts: ^2.3.1 to google_fonts: 2.3.1)
then flutter clean && pub get.
I had the same problem but it was not an issue with dependencies as for others. I stopped getting this error when I put "shape" in the scope of styles.
Example with my problem:
ElevatedButton(
child: Text('Sign in with Google'),
onPressed: _signInWithGoogle,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white,
foregroundColor: Colors.black,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0),
),
),
Example when "shape" stopped giving an error:
ElevatedButton(
child: Text('Sign in with Google'),
onPressed: _signInWithGoogle,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white,
foregroundColor: Colors.black,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0),
),
),
),

In flutter when camera is opened from image picker the app "Lost connection to device."

When I go through opening up the camera to set profile image using image picker, the app crashes and I lost connection to device
:
When pick up image from gallery its working fine,
my pubspec.yaml
name: flutterapp
description: A new Flutter project.
# Prevent accidental publishing to pub.dev.
publish_to: 'none'
version: 1.0.0+1
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
connectivity: ^3.0.6
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
font_awesome_flutter:
geolocator: ^7.7.0
http: ^0.13.4
image_picker: ^0.8.4+3
local_auth: ^1.1.8
path_provider: ^2.0.5
pdf: ^3.6.0
permission_handler: ^8.2.5
shared_preferences: ^2.0.8
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^1.0.0
flutter:
uses-material-design: true
# Enable generation of localized Strings from arb files.
generate: true
assets:
# Add assets from the images directory to the application.
- assets/
If you are using an iOS device then you have to add permission for image picking. Add these line in your info.plist file.
<key>NSCameraUsageDescription</key>
<string>Access to take a photo by camera</string>
<key>NSAppleMusicUsageDescription</key>
<string>Access to pick a photo</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Access to pick a photo</string>
I had the same problem and i check the state of memory, and yes, this case happen beacuse the memory Ram of the device is full and close the task automaticly, so .
I check the state memory in the observatory of flutter, you press "Ctrl + Shift + P" when the aplication is running and write observatory for see the state of memory of the device enter image description here enter image description here
I defined the cacheHeight and cacheWidth with the atribbute of Image.file widget and i modified the filterQuality atributte in none:
Image.file(
File(path),
filterQuality: FilterQuality.none,
cacheHeight: 66,
cacheWidth: 50,
)
Excuseme for my english.
Run your code on another device then it can work properly.
The first time I used 'Xiaomi Note 7 pro' but shows the same error after run the code on another device its work properly. Also, you can update the version of your image_picker.
It's worked for me and I used:
image_picker: ^0.8.4+1
Flutter version: 2.2.3
void _pickImageCamera() async {
final picker = ImagePicker();
final pickedImage =
await picker.pickImage(source: ImageSource.camera, imageQuality: 90);
final pickedImageFile = File(pickedImage!.path);
setState(() {
_pickedImage = pickedImageFile;
});
Navigator.pop(context); }
Try below code hope its helpful to you. In below code I used picked image using Camera as well as Gallery
Declare File type form dart.io package
File? imagePicked;
Create Function for pick up the image from Gallery
void gallaryImage() async {
final picker = ImagePicker();
final pickedImage = await picker.pickImage(
source: ImageSource.gallery,
);
final pickedImageFile = File(pickedImage!.path);
setState(() {
imagePicked = pickedImageFile;
});
}
Create Function for pick up the image from Camera
void cameraImage() async {
final picker = ImagePicker();
final pickedImage = await picker.pickImage(
source: ImageSource.camera,
);
final pickedImageFile = File(pickedImage!.path);
setState(() {
imagePicked = pickedImageFile;
});
}
Create your Widget
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextButton.icon(
onPressed: cameraImage,
label: Text(
'Camera',
style: TextStyle(
color: Colors.black,
),
),
icon: Icon(
Icons.camera,
),
),
TextButton.icon(
onPressed: gallaryImage,
label: Text(
'Gallery',
style: TextStyle(
color: Colors.black,
),
),
icon: Icon(Icons.image),
),
],
),
Hi I had the same issue and since my app doesn't open to the same screen from where it got crashed, I had to follow the below official approach
https://docs.flutter.dev/cookbook/plugins/picture-using-camera

Flutter Google Maps and CachedNetworkImage not working on Android emulator

I'm struggling with strange problem with Google Maps and CachedNetworkImage on Android emulator. App works perfect on iPhone simulator, but on Android emulator CachedNetworkImage and Google Maps aren't working properly.
CachedNetworkImage displays CircularProgressIndicator but not loading an image. Also size of images are less than 40k.
Widget with GoogleMaps displays empty screen and print error to console.
I did activated Google Maps API for Android and for iOS.
I did added API for Android to AndroidManifest.xml, and API for iOS into AppDelegate.swift.
My biling account is active (I also created different API KEY but with the same result):
<meta-data android:name="com.google.android.geo.API_KEY" android:value="MY_API_KEY_FOR_ANDROID"/>
I did added permission for internet:
<uses-permission android:name="android.permission.INTERNET" />
I've run couple of times
flutter clean
flutter run
I reinstalled app from emulator.
MinSdkVersion is set to 24.
compileSdkVersion is set to 30.
This is my MapWidget:
import 'dart:async';
import 'package:duty/models/announcement.dart';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
class OrderMapWidget extends StatelessWidget {
final Announcement announcement;
OrderMapWidget({required this.announcement});
#override
Widget build(BuildContext context) {
final CameraPosition position = CameraPosition(
target: LatLng(announcement.address.geoloc.latitude,
announcement.address.geoloc.longitude),
zoom: 9,
);
Set<Circle> _circle = Set.from([
Circle(
circleId:
CircleId(('circle_id_${DateTime.now().millisecondsSinceEpoch}')),
center: LatLng(announcement.address.geoloc.latitude,
announcement.address.geoloc.longitude),
radius: 8000,
strokeWidth: 2,
strokeColor: Theme.of(context).accentColor,
fillColor: Theme.of(context).accentColor.withAlpha(20),
)
]);
return Container(
height: 120,
child: GoogleMap(
mapType: MapType.normal,
onMapCreated: (GoogleMapController controller) {},
compassEnabled: false,
myLocationEnabled: false,
myLocationButtonEnabled: false,
initialCameraPosition: position,
onCameraMove: null,
circles: _circle,
zoomGesturesEnabled: false,
tiltGesturesEnabled: false,
scrollGesturesEnabled: false,
rotateGesturesEnabled: false,
),
);
}
}
And my CachedNetworkImage:
ClipOval(
child: CachedNetworkImage(
imageUrl: userData.profileImage,
progressIndicatorBuilder: (context, url, downloadProgress) =>
CircularProgressIndicator(value: downloadProgress.progress),
errorWidget: (context, url, error) => Icon(Icons.error),
),
),
My pubspec.yaml:
version: 1.0.0+1
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
intl: ^0.17.0
cloud_firestore: ^2.5.3
firebase_auth: ^3.1.3
firebase_core: ^1.7.0
flutter_google_places: ^0.3.0
google_maps_flutter: ^2.0.9
uuid: ^3.0.4
geocoding: ^2.0.1
cupertino_icons: ^1.0.2
cached_network_image: ^3.1.0
I tried using different emulators.
The error when using GoogleMaps on Android is as bellow:
E/flutter (15357): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: PlatformException(error, java.lang.IllegalStateException:
Trying to create a platform view of unregistered type: plugins.flutter.io/google_maps
E/flutter (15357): at io.flutter.plugin.platform.PlatformViewsController$1.createVirtualDisplayForPlatformView(PlatformViewsController.java:192)
Very similar issue
I've tried everything but for now nothing helped.
Once again everything works perfect on iOS but not on Android.
Thanks for any kind of help!
Matt
Ok, I look up through all of my dependencies and it seems that flutter_facebook_auth was casing the problem. Strange but after removing flutter_facebook_auth everything seems to be working. Google Maps and CachedNetworkImage are now working as they should. I had the newest version of flutter_facebook_auth, I tried to downgrade but it still was causing the problem. Only removing this dependencie resolve my problem. Strange...

can change background image of app for period of time in flutter?

i need to add changing background to my app.offer me a solution
code:
Widget testBGCarousel = new Container(
child: new Carousel(
children: [
new AssetImage('images/a.jpg'),
new AssetImage('images/b.jpg'),
new AssetImage('images/sc.jpg'),
].map((bgImg) => new Image(image: bgImg, width: 1500.0, height: 1500.0,
fit: BoxFit.cover)).toList(),
displayDuration: const Duration(seconds: 4),
),
);
pubspec.yaml :
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.0
share: ^0.5.3
flutter_webview_plugin: ^0.2.1+2
launch_review: ^1.0.1
carousel: ^0.1.0
error:
The current Dart SDK version is 2.1.0-dev.5.0.flutter-a2eb050044.
Because carousel 0.1.0 requires SDK version <2.0.0 and no versions of carousel match >0.1.0 <0.2.0, carousel ^0.1.0 is forbidden.
So, because quiz depends on carousel ^0.1.0, version solving failed.
pub get failed (1)
exit code 1
You have to check if the package is Dart 2.0 compatible, and looks like it is not : https://pub.dartlang.org/packages/carousel
I checked the issue opened : https://github.com/gbrvalerio/carousel/issues/11
The author updated the code but it was not published on pub Flutter packages repository.
So you have to add it manually, update your pubspec.yaml file
Change this:
carousel: ^0.1.0
To this:
carousel:
git:
url: git://github.com/gbrvalerio/carousel.git

Categories

Resources