How do I pass an Internationalization Object to Child Widgets in Flutter

半城伤御伤魂 提交于 2019-12-07 08:34:26

Nicolás Carrasco pointed towards a solution which was related to what was causing the problem for me by way of link to this post.

In the localization.dart file imports I had:

import 'package:hn/hnLocalization.dart';

While in the main.dart file imports I had:

import 'hnLocalization.dart';

These are not the same thing as described here

Making sure that all files are imported using relative paths vs packages resolved the problem. The distinction is that my files, not the dependencies use relative path. That part stumped at first.

Now my localization.dart file has the following.

import 'hnLocalization.dart'; // <--- Using relative Path

class PanelArea extends StatelessWidget {

        @override
        Widget build(BuildContext context) { ...

        child: new Column(
            children: [
                new Image.asset('assets/Icon_Intro_login'),

                // This Now Works --->
                new Text(HnLocalizations.of(context).s1M1HeaderTitle,
            ] 
       ...

and all is right now.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!