首页 > 其他 > 详细

InheritedWidget

时间:2019-04-12 14:14:33      阅读:227      评论:0      收藏:0      [点我收藏+]

 

 

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return RootWidget(
      child: MaterialApp(
        debugShowCheckedModeBanner: false,
        title: ‘V2EX app‘,
        theme: ThemeData(
          primarySwatch: Colors.grey,
        ),
        initialRoute: ‘/‘,
        routes: {
          ‘/‘: (context) => HomePage(),
          ‘/nodes‘: (context) => NodePage(),
          ‘/test‘: (context) => TestApp(),
//          ‘/web‘: (context) => WebTest(),
        },
      ),
      bloc: UserBloc(),
    );
  }
}

  

 

class RootWidget extends InheritedWidget {
  RootWidget({this.bloc, this.child}) : super(child: child);
  final UserBloc bloc;
  final Widget child;

  static RootWidget of(BuildContext context) =>
      (context).inheritFromWidgetOfExactType(RootWidget);

  @override
  bool updateShouldNotify(InheritedWidget oldWidget) {
    return true;
  }
}

  

InheritedWidget

原文:https://www.cnblogs.com/pythonClub/p/10695598.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!