Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The getter 'data' was called on null. #14

Closed
byrek3d opened this issue Jul 20, 2019 · 1 comment
Closed

The getter 'data' was called on null. #14

byrek3d opened this issue Jul 20, 2019 · 1 comment

Comments

@byrek3d
Copy link

byrek3d commented Jul 20, 2019

I am trying to add localization to my already existing package, but I am stuck with this error:

flutter: The following NoSuchMethodError was thrown building MyApp(dirty):
flutter: The getter 'data' was called on null.
flutter: Receiver: null
flutter: Tried calling: data

My main looks like this:

import 'package:flutter/material.dart';
import 'package:time_sheet/services/authentication.dart';
import 'package:time_sheet/pages/root_page.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter_localizations/flutter_localizations.dart';


void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var data = EasyLocalizationProvider.of(context).data;
    return EasyLocalizationProvider(
        data: data,
        child: MaterialApp(
        title: 'Flutter login demo',
        localizationsDelegates: [
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          //app-specific localization
          EasylocaLizationDelegate(
              locale: data.locale ?? Locale('en', 'US'),
              path: 'resources/langs'),
        ],
        supportedLocales: [Locale('en', 'US'), Locale('fr', 'CH')],
        locale: data.locale,
        debugShowCheckedModeBanner: false,
        theme: new ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: new RootPage(auth: new Auth())));
  }
}
@byrek3d
Copy link
Author

byrek3d commented Jul 20, 2019

It was my bad, I messed up the first line. I needed to have

void main() => runApp(EasyLocalization(child: MyApp()));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant