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

国际化的问题 按照步骤添加了国际化 但是报错 #89

Closed
Gyueqi opened this issue Nov 6, 2019 · 18 comments
Closed

国际化的问题 按照步骤添加了国际化 但是报错 #89

Gyueqi opened this issue Nov 6, 2019 · 18 comments

Comments

@Gyueqi
Copy link

Gyueqi commented Nov 6, 2019

import 'package:fluintl/fluintl.dart' ;
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:star_cloud_river/config/application.dart';
import 'package:star_cloud_river/config/router_river.dart';
import 'package:star_cloud_river/constant/string.dart';

void main() => runApp(RiverApp());

class RiverApp extends StatelessWidget {
RiverApp() {
final router = Router();
Routers.configureRoutes(router);
Application.router = router;
}

@OverRide
void initState() {
setLocalizedValues(localizedValues);
}

@OverRide
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primaryColor: Color(0xff2ea0f8),
),
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
CustomLocalizations.delegate //设置本地化代理
],
supportedLocales: CustomLocalizations.supportedLocales,
debugShowCheckedModeBanner: false,
onGenerateRoute: Application.router.generator,
);
}
}

I/flutter ( 9161): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 9161): The following assertion was thrown building MaterialApp(dirty, state: _MaterialAppState#e3a1e):
I/flutter ( 9161): 'package:flutter/src/widgets/app.dart': Failed assertion: line 216 pos 15: 'supportedLocales != null
I/flutter ( 9161): && supportedLocales.isNotEmpty': is not true.
I/flutter ( 9161):
I/flutter ( 9161): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter ( 9161): more information in this error message to help you determine and fix the underlying cause.
I/flutter ( 9161): In either case, please report this assertion by filing a bug on GitHub:
I/flutter ( 9161): https://github.com/flutter/flutter/issues/new?template=BUG.md
I/flutter ( 9161):
I/flutter ( 9161): User-created ancestor of the error-causing widget was:
I/flutter ( 9161): RiverApp file:///Users/work/ZYProjects/XJYH/lib/main.dart:9:23
I/flutter ( 9161):
I/flutter ( 9161): When the exception was thrown, this was the stack:
I/flutter ( 9161): #2 new WidgetsApp (package:flutter/src/widgets/app.dart:216:15)
I/flutter ( 9161): #3 _MaterialAppState.build (package:flutter/src/material/app.dart:552:21)
I/flutter ( 9161): #4 StatefulElement.build (package:flutter/src/widgets/framework.dart:4047:27)
I/flutter ( 9161): #5 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3941:15)
I/flutter ( 9161): #6 Element.rebuild (package:flutter/src/widgets/framework.dart:3738:5)
I/flutter ( 9161): #7 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3924:5)
I/flutter ( 9161): #8 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4088:11)
I/flutter ( 9161): #9 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3919:5)
I/flutter ( 9161): #10 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3101:14)
I/flutter ( 9161): #11 Element.updateChild (package:flutter/src/widgets/framework.dart:2904:12)
I/flutter ( 9161): #12 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3961:16)
I/flutter ( 9161): #13 Element.rebuild (package:flutter/src/widgets/framework.dart:3738:5)
I/flutter ( 9161): #14 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3924:5)
I/flutter ( 9161): #15 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3919:5)
I/flutter ( 9161): #16 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3101:14)
I/flutter ( 9161): #17 Element.updateChild (package:flutter/src/widgets/framework.dart:2904:12)
I/flutter ( 9161): #18 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:998:16)
I/flutter ( 9161): #19 RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:969:5)
I/flutter ( 9161): #20 RenderObjectToWidgetAdapter.attachToRenderTree. (package:flutter/src/widgets/binding.dart:915:17)
I/flutter ( 9161): #21 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2328:19)
I/flutter ( 9161): #22 RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:914:13)
I/flutter ( 9161): #23 WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:795:7)
I/flutter ( 9161): #24 runApp (package:flutter/src/widgets/binding.dart:845:7)
I/flutter ( 9161): #25 main (package:star_cloud_river/main.dart:9:16)
I/flutter ( 9161): #26 _runMainZoned.. (dart:ui/hooks.dart:229:25)
I/flutter ( 9161): #31 _runMainZoned. (dart:ui/hooks.dart:221:5)
I/flutter ( 9161): #32 _startIsolate. (dart:isolate-patch/isolate_patch.dart:305:19)
I/flutter ( 9161): #33 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
I/flutter ( 9161): (elided 6 frames from class _AssertionError and package dart:async)
I/flutter ( 9161):
I/flutter ( 9161): ════════════════════════════════════════════════════════════════════════════════════════════════════
D/EGL_emulation( 9161): eglMakeCurrent: 0xe3305b40: ver 3 0 (tinfo 0xe3303970)

@Gyueqi
Copy link
Author

Gyueqi commented Nov 6, 2019

supportedLocales: CustomLocalizations.supportedLocales,//设置支持本地化语言集合 这句话 更改成 supportedLocales: [
const Locale('zh', 'CH'),
const Locale('en', 'US'),
], 这样APP 可以启动 但是text取不到值

@Sky24n
Copy link
Owner

Sky24n commented Nov 6, 2019

StatelessWidget 有initState这个方法吗?

MaterialApp(  
   home: MyHomePage(),  
   localizationsDelegates: [  
   GlobalMaterialLocalizations.delegate,  
   GlobalWidgetsLocalizations.delegate,  
   CustomLocalizations.delegate //设置本地化代理     
   ],  
   supportedLocales: CustomLocalizations.supportedLocales,//设置支持本地化语言集合     
);  

@Gyueqi
Copy link
Author

Gyueqi commented Nov 6, 2019

import 'package:fluintl/fluintl.dart' ;
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:star_cloud_river/common/common.dart';
import 'package:star_cloud_river/common/sp_helper.dart';
import 'package:star_cloud_river/config/application.dart';
import 'package:star_cloud_river/config/router_river.dart';
import 'package:star_cloud_river/constant/string.dart';
import 'package:star_cloud_river/models/models.dart';

void main() => runApp(RiverApp());

class RiverApp extends StatefulWidget {
@OverRide
State createState() {
return RiverAppState();
}
}

class RiverAppState extends State {
Locale _locale;

RiverApp() {
final router = Router();
Routers.configureRoutes(router);
Application.router = router;
}

void _loadLocale() {
setState(() {
LanguageModel model =
SpHelper.getObject(Constant.keyLanguage);
if (model != null) {
_locale = new Locale(model.languageCode, model.countryCode);
} else {
_locale = null;
}
});
}
@OverRide
void initState() {
super.initState();
setLocalizedValues(localizedValues);
}

@OverRide
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
onGenerateRoute: Application.router.generator,
theme: ThemeData(
primaryColor: Color(0xff2ea0f8),
),
locale: _locale,
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
CustomLocalizations.delegate //设置本地化代理
],
supportedLocales: CustomLocalizations.supportedLocales,
);
}
}

@Gyueqi
Copy link
Author

Gyueqi commented Nov 6, 2019

改了 但是还是这个问题

@Sky24n
Copy link
Owner

Sky24n commented Nov 6, 2019

现在具体是什么问题?有没有截图之类的

@Gyueqi
Copy link
Author

Gyueqi commented Nov 6, 2019

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following NoSuchMethodError was thrown building LanguagePage(dirty, state: _LanguagePageState#2fe06):
The getter 'bloc' was called on null.
Receiver: null
Tried calling: bloc

User-created ancestor of the error-causing widget was:
MaterialApp file:///Users/work/ZYProjects/XJYH/lib/main.dart:63:12
When the exception was thrown, this was the stack:
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 BlocProvider.of (package:star_cloud_river/blocs/bloc_provider.dart:31:21)
#2 _LanguagePageState.build (package:star_cloud_river/page/page_me/setup/language_page.dart:46:47)
#3 StatefulElement.build (package:flutter/src/widgets/framework.dart:4047:27)
#4 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3941:15)
...

@Gyueqi
Copy link
Author

Gyueqi commented Nov 6, 2019

1573040463626

@Sky24n
Copy link
Owner

Sky24n commented Nov 6, 2019

资源文件呢

@Gyueqi
Copy link
Author

Gyueqi commented Nov 7, 2019

image
image
请问 为什么MAIN 突然报错 之前都是好的 现在加载H5 报错String 不是一个组件

@Sky24n
Copy link
Owner

Sky24n commented Nov 7, 2019

错误信息很清楚啊!parameters[xxx] 是null,无法取值

@Gyueqi
Copy link
Author

Gyueqi commented Nov 7, 2019

我没有改变main 的时候是可以取值的 但是加了国际化 然后变成StatefulWidget 后就取值不到了,。

@Gyueqi
Copy link
Author

Gyueqi commented Nov 7, 2019

image
之前是这样的 这样路由是可以取值的

@Sky24n
Copy link
Owner

Sky24n commented Nov 7, 2019

大哥,下次好好检查下代码!

class RiverAppState extends State {
Locale _locale;
/// 这个方法都没有运行!!!
RiverApp() {
final router = Router();//放到 initState
Routers.configureRoutes(router);//initState
Application.router = router;//initState
}

改

@override
void initState() {
super.initState();
final router = Router();
Routers.configureRoutes(router);
Application.router = router;
setLocalizedValues(localizedValues);
}

@Gyueqi
Copy link
Author

Gyueqi commented Nov 7, 2019

image
有调用的 这边 然后方法也进了

@Gyueqi
Copy link
Author

Gyueqi commented Nov 7, 2019

是因为顺序的问题???

@Gyueqi
Copy link
Author

Gyueqi commented Nov 7, 2019

image
按照老哥你这边的没用方法调用 直接写进去 也一样的 这个我调试过的 老哥

@Sky24n
Copy link
Owner

Sky24n commented Nov 7, 2019

最后这样试试吧!再不行我也没有办法了!

void main()  {
final router = Router();
Routers.configureRoutes(router);
Application.router = router;
runApp(RiverApp());
}

@Gyueqi
Copy link
Author

Gyueqi commented Nov 7, 2019

好的 我试试 谢谢老哥的解答

@Sky24n Sky24n closed this as completed May 8, 2020
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

2 participants