第三方组件技巧

Posted by アライさん on 2020年06月23日

第三方组件技巧

fluro

main.dart初始化

1
2
3
MaterialApp(
initialRoute: Routes.root,
onGenerateRoute: Routes.router.generator),

跳转登录,清除页面栈

1
2
3
Navigator.of(context).popUntil(ModalRoute.withName(Routes.root));
Routes.router.navigateTo(
context, '${Routes.loginInputPhone}?phoneNumber=$phoneNumber');

传递复杂数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//跳转并接受返回
final json =jsonEncode(itemData);
final encodeStr =Uri.encodeComponent(json);
Routes.router.navigateTo(context, '${Routes.modifyUserAddress}?address=$encodeStr')
.then((value) {}}).catchError((error) {});

//接收
var modifyUserAddressHandler = new Handler(
handlerFunc: (BuildContext context, Map<String, List<String>> params) {

if (params != null || params.length <= 0) {
AddressItemData addressItem = AddressItemData.fromJson(
jsonDecode(paramsStr) ?? '');
return ModifyUsrAddressPage(addressData: addressItem,);
}
}

event_bus

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import 'package:event_bus/event_bus.dart';

class EventBusUtil {
static EventBus _eventBus;

static EventBus getInstance() {
if (_eventBus == null) {
_eventBus = new EventBus();
}
return _eventBus;
}
}
EventBusUtil.getInstance().fire(TokenLoginOutEvent());
EventBusUtil.getInstance().on<TokenLoginOutEvent>().listen((event) {});