Flutter app slow

debug mode launch is slow blink when launch app size big. because debug mode with Hot reloads. when you create release apk https://flutter.io/docs/deployment/android you can find fast launch no blink during the launch app size small (but bigger than the normal android app) EDIT https://flutter.io/docs/testing/ui-performance#debug-flags Debug mode enables additional checks (such as asserts) that don’t … Read more

how can we use superscript and subscript text in flutter Text or RichText

You need to use Unicode. Here is the Unicode got from this answer: unicode_map = { # superscript subscript ‘0’ : (‘\u2070’, ‘\u2080’ ), ‘1’ : (‘\u00B9’, ‘\u2081’ ), ‘2’ : (‘\u00B2’, ‘\u2082’ ), ‘3’ : (‘\u00B3’, ‘\u2083’ ), ‘4’ : (‘\u2074’, ‘\u2084’ ), ‘5’ : (‘\u2075’, ‘\u2085’ ), ‘6’ : (‘\u2076’, ‘\u2086’ ), ‘7’ … Read more

What’s the difference between pub dependencies and dev_dependencies?

dev_dependencies are dependencies that are not available for code in the resulting application, but only for tests, examples, tools, or to add executable tools like for code generation to your project. dev_dependencies of any dependencies in your project (dependencies or dev_dependencies) are always ignored when you publish to pub.dev. See also https://dart.dev/tools/pub/pubspec

Default values of an optional parameter must be constant

Try enum MyEnum { a, b } class ClassA { final MyEnum myEnum; ClassA({this.myEnum}); } class ClassB { final ClassA classA; ClassB({this.classA}); // ClassA expression is underlined with red } no need for ‘=’ operator. It will automatically assign the value when you will pass it to the constructor. Use the ‘=’ operator only when … Read more

How to get widget’s absolute coordinates on a screen in Flutter?

You can use this extension I wrote (requires Dart 2.6): extension GlobalKeyExtension on GlobalKey { Rect? get globalPaintBounds { final renderObject = currentContext?.findRenderObject(); final translation = renderObject?.getTransformTo(null).getTranslation(); if (translation != null && renderObject?.paintBounds != null) { final offset = Offset(translation.x, translation.y); return renderObject!.paintBounds.shift(offset); } else { return null; } } } Example how to use … Read more

How to read and write a text file in Flutter

Setup Add the following plugin in pubspec.yaml: dependencies: path_provider: ^1.6.27 Update the version number to whatever is current. And import it in your code. import ‘package:path_provider/path_provider.dart’; You also have to import dart:io to use the File class. import ‘dart:io’; Writing to a text file _write(String text) async { final Directory directory = await getApplicationDocumentsDirectory(); final … Read more

Flutter: Default assignment of List parameter in a constructor

Default values currently need to be const. This might change in the future. If your default value can be const, adding const would be enough class sample{ final int x; final List<String> y; sample({this.x = 0, this.y = const [“y”,”y”,”y”,”y”]}); } Dart usually just assumes const when const is required, but for default values this … Read more

Cancel stream onData

The issue is that I can’t access the variable subscription in the body of my callback, since it is still not created at the time That’s correct – you cannot access is the subscription variable, even if you know that the subscription itself would exist. Dart doesn’t allow variables declarations to refer to themselves. That’s … Read more