一 Flutter学习 状态管理( 二 )

(stream: bloc.stream,initialData: bloc.value,//获取初始化的值builder: (BuildContext context, AsyncSnapshot snapshot) {return Text('You hit me:${snapshot.data} times',//取出datastyle: Theme.of(context).textTheme.display1,//小字体,display2是中字体...);}),),floatingActionButton: FloatingActionButton(child: Icon(Icons.navigate_next),//跳到下个页面onPressed: ()=>Navigator.of(context).push(MaterialPageRoute(builder: (context)=>UnderPage())),),);}}
5. :
import 'package:flutter/material.dart';import 'package:flutter_bloctest/BlocProvider.dart';class UnderPage extends StatelessWidget {@overrideWidget build(BuildContext context) {final bloc = BlocProvider.of(context);print("build");return Scaffold(appBar: AppBar(title: Text('Under Page'),),body: Center(child: StreamBuilder(stream: bloc.stream,initialData: bloc.value,builder: (BuildContext context, AsyncSnapshot snapshot) => Text("You hit me : ${snapshot.data} times",style: Theme.of(context).textTheme.display1,)),),floatingActionButton: FloatingActionButton(onPressed: () => bloc.increment(),//调用添加value的那个函数child: Icon(Icons.add),),);}}
附上:
参考资料:
【一Flutter学习 状态管理】#/zh-CN//icon