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

fix: install.md 中 dart 代码无法运行 #2160

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ import 'package:flutter_boost/flutter_boost.dart';
void main() {
///这里的CustomFlutterBinding调用务必不可缺少,用于控制Boost状态的resume和pause
CustomFlutterBinding();
runApp(MyApp());
runApp(const MyApp());
}


///创建一个自定义的Binding,继承和with的关系如下,里面什么都不用写
class CustomFlutterBinding extends WidgetsFlutterBinding with BoostFlutterBinding {}

class MyApp extends StatefulWidget {
const MyApp({super.key});

@override
_MyAppState createState() => _MyAppState();
State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
Expand All @@ -59,18 +61,21 @@ class _MyAppState extends State<MyApp> {
/// 如果用MaterialPageRoute的话同理

Map<String, FlutterBoostRouteFactory> routerMap = {
'mainPage': (RouteSettings settings, String uniqueId) {
'mainPage': (RouteSettings settings, bool isContainerPage, String? uniqueId) {
return CupertinoPageRoute(
settings: settings,
builder: (_) {
Map<String, Object> map = settings.arguments as Map<String, Object> ;
String data = map['data'] as String;
Map<String, dynamic> map = settings.arguments as Map<String, dynamic>;
Object? data;
if (map.containsKey('data')) {
data = map['data'];
}
return MainPage(
data: data,
);
});
},
'simplePage': (settings, uniqueId) {
'simplePage': (settings, isContainerPage, uniqueId) {
return CupertinoPageRoute(
settings: settings,
builder: (_) {
Expand All @@ -83,9 +88,13 @@ class _MyAppState extends State<MyApp> {
},
};

Route<dynamic> routeFactory(RouteSettings settings, String uniqueId) {
FlutterBoostRouteFactory func = routerMap[settings.name] as FlutterBoostRouteFactory;
return func(settings, uniqueId);
Route<dynamic>? routeFactory(RouteSettings settings, bool isContainerPage, String? uniqueId) {
var key = settings.name;
if (!routerMap.containsKey(key)) {
key = 'mainPage'; // 如果不在路由表中,就默认跳转到mainPage
}
FlutterBoostRouteFactory func = routerMap[key] as FlutterBoostRouteFactory;
return func(settings, isContainerPage, uniqueId);
}

Widget appBuilder(Widget home) {
Expand All @@ -110,7 +119,7 @@ class _MyAppState extends State<MyApp> {
}

class MainPage extends StatelessWidget {
const MainPage({Object data});
const MainPage({super.key, Object? data});
@override
Widget build(BuildContext context) {
return const Scaffold(
Expand All @@ -120,11 +129,11 @@ class MainPage extends StatelessWidget {
}

class SimplePage extends StatelessWidget {
const SimplePage({Object data});
const SimplePage({super.key, Object? data});
@override
Widget build(BuildContext context) {
return const Scaffold(
body: Center(child: Text('SimplePage')),
body: Center(child: Text('SimplePage')),
);
}
}
Expand Down