Flutter use variable created inside Future builder outside of the build method,

I don’t fully understand the reason to have a global TextController (and I don’t think its a good idea either) but using Riverpod it would look somethink like this: import ‘package:flutter/material.dart’; import ‘package:flutter_riverpod/flutter_riverpod.dart’; class AccountData { final String firstName; final String lastName; final String phoneNumber; AccountData({ required this.firstName, required this.lastName, required this.phoneNumber, }); factory AccountData.fromJson(Map<String, … Read more

Update flutter dependencies in /.pub-cache

Disclaimer: By running the command below, have a really fast internet connection or be ready to lose one hour of productive hours. ( it will redownload every package every installed on your pc, and I mean each and all of the versions of each packages)~TSR flutter pub cache repair or delete /Users/xxxxxxx/development/tools/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.8.2+3/ and run flutter … Read more

How to get unique device id in flutter?

Null safe code Use device_info_plus plugin developed by Flutter community. This is how you can get IDs on both platform. In your pubspec.yaml file add this: dependencies: device_info_plus: ^3.2.3 Create a method: Future<String?> _getId() async { var deviceInfo = DeviceInfoPlugin(); if (Platform.isIOS) { // import ‘dart:io’ var iosDeviceInfo = await deviceInfo.iosInfo; return iosDeviceInfo.identifierForVendor; // unique … Read more

Do not use BuildContexts across async gaps

Don’t stock context directly into custom classes, and don’t use context after async if you’re not sure your widget is mounted. Do something like this: class MyCustomClass { const MyCustomClass(); Future<void> myAsyncMethod(BuildContext context, VoidCallback onSuccess) async { await Future.delayed(const Duration(seconds: 2)); onSuccess.call(); } } class MyWidget extends StatefulWidget { @override _MyWidgetState createState() => _MyWidgetState(); } … Read more

Flutter App stuck at “Running Gradle task ‘assembleDebug’… “

Here is solution in my case. Open your flutter Project directory. Change directory to android directory in your flutter project directory cd android clean gradle ./gradlew clean Build gradle ./gradlew build or you can combine both commands with just ./gradlew clean build Now run your flutter project. If you use vscode, press F5. First time … Read more

How to change status bar color in Flutter?

Update Flutter 2.0 (Recommended): On latest Flutter version, you should use: AppBar( systemOverlayStyle: SystemUiOverlayStyle( // Status bar color statusBarColor: Colors.red, // Status bar brightness (optional) statusBarIconBrightness: Brightness.dark, // For Android (dark icons) statusBarBrightness: Brightness.light, // For iOS (dark icons) ), ) Only Android (more flexibility): import ‘package:flutter/services.dart’; void main() { SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle( systemNavigationBarColor: Colors.blue, // navigation … Read more