fluro

fluro导航示例程序:

分了4个文件:

1:main.dart: 主入口文件;

2:routes.dart 路径文件;

3:pageone.dart

4:pagetwo.dart

 

 

main.dart

import 'package:flutter/material.dart';
import 'package:fluro/fluro.dart';
import 'routes.dart';

///启动
void main() {
///初始化并配置路由
final router = Router();
Routes.configureRoutes(router);
runApp(
MaterialApp(
onGenerateRoute: Routes.router.generator
)
);
}




routes.dart
import 'package:fluro/fluro.dart';
import 'pagetwo.dart';
import 'pageone.dart';

class Routes {
static Router router;

static void configureRoutes(Router router) {
router.define(
'/', handler: Handler(handlerFunc: (context, params) => Page1()));
router.define(
'/page2', handler: Handler(handlerFunc: (context, params) {
return Page2(params['data'][0]);
}));
Routes.router = router;
}
}



pageone.dart
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'routes.dart';
import 'dart:convert';

///第一个界面
class Page1 extends StatefulWidget {
@override
State<StatefulWidget> createState() => Page1State();
}

class Page1State extends State<Page1> {
String fuck = '一';

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('第一个页面'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.chevron_right),
onPressed: () => intentTo(context)
)
],
),
body: Center(
child: Text(fuck)
),
);
}

///跳转到第二个界面
intentTo(BuildContext context) {
///字符串编码
var json = jsonEncode(Utf8Encoder().convert('来自第一个界面'));
Routes.router.navigateTo(
context, '/page2?data=$json',//跳转路径
transition: TransitionType.inFromRight//过场效果
).then((result) {//回传值
if (result != null) {
fuck = result;
}
});
}
}



pagetwo.dart
import 'package:flutter/material.dart';
import 'dart:convert';

///第二个界面
class Page2 extends StatelessWidget {
final String datas;

const Page2(this.datas);

@override
Widget build(BuildContext context) {
var list = List<int>();
///字符串解码
jsonDecode(datas).forEach(list.add);
final String value = Utf8Decoder().convert(list);
return Scaffold(
appBar: AppBar(
title: Text('第二个页面'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(value),
RaisedButton(
onPressed: () => Navigator.pop(context, '来自第二个界面'),
child: Text('返回上一个界面')
)
],
)
)
);
}
}


posted @ 2019-06-03 16:17  braveheart007  阅读(411)  评论(0编辑  收藏  举报