Instantiate a class from a string

You need to know the library name and class name to make things work properly. Assume you know both, the below example will instantiate the TestClass and call doStuff on it. library test; import “dart:mirrors”; class TestClass { doStuff() => print(“doStuff was called!”); } main() { MirrorSystem mirrors = currentMirrorSystem(); LibraryMirror lm = mirrors.libraries[‘test’]; ClassMirror … Read more

Custom AppBar Flutter

Screenshot: Code: Using flexibleSpace Scaffold( appBar: AppBar( toolbarHeight: 120, // Set this height flexibleSpace: Container( color: Colors.orange, child: Column( children: [ Text(‘One’), Text(‘Two’), Text(‘Three’), Text(‘Four’), ], ), ), ), ) Using PreferredSize Scaffold( appBar: PreferredSize( preferredSize: Size.fromHeight(120), // Set this height child: Container( color: Colors.orange, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text(‘One’), Text(‘Two’), Text(‘Three’), Text(‘Four’), … Read more

Flutter: Ignore touch events on a Widget

Solution You can solve your interaction issue (not being able to interact with the Widget below your blurred image) by surrounding your BackdropFilter with an IgnorePointer. This means that IgnorePointer is the solution here because it will ignore all touch events for the Widget‘s passed as its child. IgnorePointer(child: BackdropFilter(…),) You can adjust this attribute … Read more

How to clear Flutter’s Build cache?

You can run flutter clean. But that’s most likely a problem with your IDE or similar, as flutter run creates a brand new apk. And hot reload push only modifications. Try running your app using the command line flutter run and then press r or R for respectively hot-reload and full-reload.

Logging large strings from Flutter

How about using the Flutter log from the dart: developer library. This does not seem to have the maximum length limit like print() or debugPrint(). This is the only solution that seems to work fine. Try it as below: import ‘dart:developer’; log(reallyReallyLongText); The output will be the entire long string without breaks and prefixed with … Read more

The return type ‘void’ isn’t assignable to ‘FutureOr’, as required by ‘Future.catchError’

The documentation for Future.catchError could be a lot clearer, but the relevant part is: onError is called with the error and possibly stack trace, and the returned future is completed with the result of this call in exactly the same way as for then‘s onError. Cross-referencing to the documentation for Future.then, the relevant portion is: … Read more

How do I extend a List in Dart?

To make a class implement List there are several ways : Extending ListBase and implementing length, operator[], operator[]= and length= : import ‘dart:collection’; class MyCustomList<E> extends ListBase<E> { final List<E> l = []; MyCustomList(); void set length(int newLength) { l.length = newLength; } int get length => l.length; E operator [](int index) => l[index]; void … Read more

Flutter: Update Widgets On Resume?

You can listen to lifecycle events by doing this for example : import ‘package:flutter/material.dart’; import ‘package:flutter/foundation.dart’; class LifecycleEventHandler extends WidgetsBindingObserver { final AsyncCallback resumeCallBack; final AsyncCallback suspendingCallBack; LifecycleEventHandler({ this.resumeCallBack, this.suspendingCallBack, }); @override Future<void> didChangeAppLifecycleState(AppLifecycleState state) async { switch (state) { case AppLifecycleState.resumed: if (resumeCallBack != null) { await resumeCallBack(); } break; case AppLifecycleState.inactive: case AppLifecycleState.paused: … Read more