-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[Bug]: 启动不了 #2106
Comments
控制台日志
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart';
void main() {
///这里的CustomFlutterBinding调用务必不可缺少,用于控制Boost状态的resume和pause
CustomFlutterBinding();
final List<Locale> supportedLocales = [
const Locale('en'),
const Locale('zh'),
const Locale('ar'),
];
const fallbackLocale = Locale('en');
runApp(EasyLocalization(
fallbackLocale: fallbackLocale,
supportedLocales: supportedLocales,
startLocale: const Locale('en'),
path: 'assets/langs',
child: const MyApp(),
));
}
class CustomFlutterBinding extends WidgetsFlutterBinding
with BoostFlutterBinding {}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
/// 由于很多同学说没有跳转动画,这里是因为之前exmaple里面用的是 [PageRouteBuilder],
/// 其实这里是可以自定义的,和Boost没太多关系,比如我想用类似iOS平台的动画,
/// 那么只需要像下面这样写成 [CupertinoPageRoute] 即可
/// (这里全写成[MaterialPageRoute]也行,这里只不过用[CupertinoPageRoute]举例子)
///
/// 注意,如果需要push的时候,两个页面都需要动的话,
/// (就是像iOS native那样,在push的时候,前面一个页面也会向左推一段距离)
/// 那么前后两个页面都必须是遵循CupertinoRouteTransitionMixin的路由
/// 简单来说,就两个页面都是CupertinoPageRoute就好
/// 如果用MaterialPageRoute的话同理
Map<String, FlutterBoostRouteFactory> routerMap = {
'mainPage': (RouteSettings settings, String? uniqueId) {
return CupertinoPageRoute(
settings: settings,
builder: (_) {
// Map<String, Object>? map = settings.arguments as Map<String, Object>;
// String data = map['data'] as String;
return const MainPage(
data: '123',
);
});
},
'simplePage': (settings, uniqueId) {
return CupertinoPageRoute(
settings: settings,
builder: (_) {
Map<String, Object> map = settings.arguments as Map<String, Object>;
String data = map['data'] as String;
return SimplePage(
data: data,
);
});
},
};
Route<dynamic>? routeFactory(RouteSettings settings, String? uniqueId) {
FlutterBoostRouteFactory func =
routerMap[settings.name] as FlutterBoostRouteFactory;
return func(settings, uniqueId);
}
Widget appBuilder(Widget home) {
return MaterialApp(
home: home,
debugShowCheckedModeBanner: true,
/// 这三行注释, 就可以
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale,
///必须加上builder参数,否则showDialog等会出问题
builder: (_, __) {
return home;
},
);
}
@override
Widget build(BuildContext context) {
return FlutterBoostApp(routeFactory,
appBuilder: appBuilder, initialRoute: 'mainPage');
}
}
class MainPage extends StatelessWidget {
const MainPage({super.key, required Object data});
@override
Widget build(BuildContext context) {
return const Scaffold(
body: Center(child: Text('Main Page')),
);
}
}
class SimplePage extends StatelessWidget {
const SimplePage({super.key, required Object data});
@override
Widget build(BuildContext context) {
return const Scaffold(
body: Center(child: Text('SimplePage')),
);
}
}
|
将原先在initState中进行的初始化,改放到确保Overlay被mounted之后的时序中
这单纯就是Boost框架的问题吧,和initRoute也没关系,只是对MaterialApp中设置了locale后没做好兼容的问题。 而且为什么会有内部关键逻辑理解产生问题?关键逻辑没变吧,一直都是启动时获取已经挂载的Overlay然后做后续初始化,现在的PR也只是确保初始化时Overlay一定被挂载了。 |
@joechan-cq 这边建议可以自行拉分支修复~~主仓库暂不考虑修复哈 |
我混合项目使用了flutter_screenutil,也是必白屏,去掉就不会了 |
如果报错也是一样的,那原因应该也一样,screenutil的build方法,内部有延迟挂载的逻辑。 |
请描述遇到的问题,以及您所期望的正确的结果
日志如下
请说明如何操作会遇到上述问题
No response
在下面填入关键复现代码
复现的平台
Both
Flutter SDK版本
3.22.2
FlutterBoost版本
4.6.2
是否延迟初始化FlutterBoost
No
解决方案
No response
The text was updated successfully, but these errors were encountered: