ilteoood/flutter_i18n

type '(BuildContext, Widget) => StreamBuilder<Locale?>' is not a subtype of type '((BuildContext, Widget?) => Widget)?'

alexrintt opened this issue · 1 comments

Hi! Thanks for your package, it's super complete and useful. I use it in my project, but I found some typing gaps:

Flutter 2.2.0 • channel stable • https://github.com/flutter/flutter.git
Framework • revision b22742018b (2 weeks ago) • 2021-05-14 19:12:57 -0700
Engine • revision a9d88a4d18
Tools • Dart 2.13.0

When I use:

MaterialApp(
  builder: FlutterI18n.rootAppBuider(),
);

It throws an exception:

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following _TypeError was thrown building AppMock(dirty):
type '(BuildContext, Widget) => StreamBuilder<Locale?>' is not a subtype of type '((BuildContext,
Widget?) => Widget)?'

It happens because the package has missing types in many places:
lib\flutter_i18n.dart

class FlutterI18n {
  /// ...
 static /** Missing return types **/ rootAppBuilder() {
    return (BuildContext context, Widget child) {
      final instance = _retrieveCurrentInstance(context);
      return StreamBuilder<Locale?>(
          initialData: instance?.locale,
          stream: instance?._localeStream.stream,
          builder: (BuildContext context, AsyncSnapshot<Locale?> snapshot) {
            return Directionality(
              textDirection: _findTextDirection(snapshot.data),
              child: child,
            );
          });
    };
  }
  /// ...
}

I opened a PR to apply the fix for this specific location, but I would like to discuss adding effective_dart to the whole package and making the entire development flow follow these rules, to minimize bugs like this and many others.

Anyway, thanks for the hard work and the awesome package!

Thank you for the PR. Any help is REALLY appreciated 😁