smartnsoft / FlappyTranslator

A tool which automatically generates Flutter localization resources from CSV and Excel files.
MIT License
57 stars 20 forks source link

I18n.of(context) returns null #25

Closed speller closed 4 years ago

speller commented 4 years ago

My code:

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

import './i18n.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var i18n = I18n.of(context);

    return MaterialApp(
      title: i18n.appTitle,
      supportedLocales: I18nDelegate.supportedLocals,
      initialRoute: '',
      routes: [],
    );
  }
}

I'm getting the following exception when running it:

I/flutter ( 5741): The getter 'appTitle' was called on null.

What I'm doing wrong?

defuncart commented 4 years ago

@speller You need to set up the localization delegates as per documentation. You can take a look at this example for more info.

defuncart commented 4 years ago

Closing this issue as code does not follow documentation or example. Please feel free to re-open if you experience any further issues.