diff --git a/assets/flutter.db b/assets/flutter.db index 87d4826..1b78caf 100644 Binary files a/assets/flutter.db and b/assets/flutter.db differ diff --git a/lib/views/pages/home/home_page.dart b/lib/views/pages/home/home_page.dart index b7eafbf..5e5fb39 100644 --- a/lib/views/pages/home/home_page.dart +++ b/lib/views/pages/home/home_page.dart @@ -31,9 +31,7 @@ class _HomePageState extends State with AutomaticKeepAliveClientMixin @override Widget build(BuildContext context) { - print('-------HomePage-------build-------'); var color = BlocProvider.of(context).state.homeColor; - var showBg = BlocProvider.of(context).state.showBackGround; return Scaffold( appBar: TolyAppBar( selectIndex: Cons.tabColors.indexOf(color.value), @@ -42,7 +40,12 @@ class _HomePageState extends State with AutomaticKeepAliveClientMixin ), body: Stack( children: [ - if (showBg) Background(), + BlocBuilder(builder: (_, state) { + if (state.showBackGround) { + return Background(); + } + return Container(); + }), BlocBuilder(builder: _buildContent) ], ), @@ -69,11 +72,16 @@ class _HomePageState extends State with AutomaticKeepAliveClientMixin Widget _buildHomeItem( WidgetModel model, ) => - FeedbackWidget( - duration: const Duration(milliseconds: 200), - onPressed: () => _toDetailPage(model), - child: HomeItemSupport.get(model, - BlocProvider.of(context).state.itemStyleIndex)); + BlocBuilder( + condition: (p, c) => (p.itemStyleIndex != c.itemStyleIndex), + builder: (_, state) { + return + FeedbackWidget( + duration: const Duration(milliseconds: 200), + onPressed: () => _toDetailPage(model), + child: HomeItemSupport.get(model, state.itemStyleIndex)); + }, + ); _updateAppBarHeight() { if (_ctrl.offset < _limitY * 4) { diff --git a/lib/views/widgets/StatelessWidget/Builder/node1_base.dart b/lib/views/widgets/StatelessWidget/Builder/node1_base.dart new file mode 100644 index 0000000..11fe021 --- /dev/null +++ b/lib/views/widgets/StatelessWidget/Builder/node1_base.dart @@ -0,0 +1,38 @@ +import 'package:flutter/material.dart'; + +/// create by 张风捷特烈 on 2020/5/3 +/// contact me by email 1981462002@qq.com +/// 说明: + +// { +// "widgetId": 202, +// "name": 'Builder的使用', +// "priority": 1, +// "subtitle": "【builder】 : 组件构造器 【WidgetBuilder】\n" +// "同一个类中使用`XXX.of(context)`获取某类状态对象方法会存在`上下文滞后`的错误,使用Builder解决。", +// } + +class BuilderDemo extends StatelessWidget { + @override + Widget build(BuildContext context) { + return Container( + height: 200, + child: Scaffold( + appBar: AppBar( + title: Text('Builder'), + ), + floatingActionButton: Builder( + builder: (ctx) => FloatingActionButton( + onPressed: () { + Scaffold.of(ctx) + .showSnackBar(SnackBar(content: Text('hello builder'))); + }, + child: Icon(Icons.add), + ), + ), + ), + ); + } + + +} diff --git a/lib/views/widgets/exp/stateless_unit.dart b/lib/views/widgets/exp/stateless_unit.dart index 063b40a..668d722 100644 --- a/lib/views/widgets/exp/stateless_unit.dart +++ b/lib/views/widgets/exp/stateless_unit.dart @@ -57,6 +57,7 @@ export '../StatelessWidget/Visibility/node2_replacement.dart'; export '../StatelessWidget/ChoiceChip/node1_base.dart'; export '../StatelessWidget/FilterChip/node1_base.dart'; +export '../StatelessWidget/Builder/node1_base.dart'; export '../StatelessWidget/ListTile/node1_base.dart'; diff --git a/lib/views/widgets/widgets_map.dart b/lib/views/widgets/widgets_map.dart index bec3e1e..0f496ca 100644 --- a/lib/views/widgets/widgets_map.dart +++ b/lib/views/widgets/widgets_map.dart @@ -739,6 +739,10 @@ class WidgetsMap { BuilderListView(), SeparatedListView(), ]; + case "Builder": + return [ + BuilderDemo(), + ]; case "GridView": return [ CustomGridView(), diff --git a/pubspec.lock b/pubspec.lock index afad29f..ad96f4d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,21 +7,21 @@ packages: name: archive url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.11" + version: "2.0.13" args: dependency: transitive description: name: args url: "https://pub.flutter-io.cn" source: hosted - version: "1.5.2" + version: "1.6.0" async: dependency: transitive description: name: async url: "https://pub.flutter-io.cn" source: hosted - version: "2.4.0" + version: "2.4.1" bloc: dependency: transitive description: @@ -35,21 +35,21 @@ packages: name: boolean_selector url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.5" + version: "2.0.0" charcode: dependency: transitive description: name: charcode url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.2" + version: "1.1.3" collection: dependency: transitive description: name: collection url: "https://pub.flutter-io.cn" source: hosted - version: "1.14.11" + version: "1.14.12" convert: dependency: transitive description: @@ -63,7 +63,7 @@ packages: name: crypto url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.3" + version: "2.1.4" cupertino_icons: dependency: "direct main" description: @@ -113,7 +113,7 @@ packages: name: image url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.4" + version: "2.1.12" intl: dependency: "direct main" description: @@ -149,13 +149,6 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.6.4" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.8.0+1" petitparser: dependency: transitive description: @@ -183,7 +176,7 @@ packages: name: quiver url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.5" + version: "2.1.3" rxdart: dependency: transitive description: @@ -237,7 +230,7 @@ packages: name: source_span url: "https://pub.flutter-io.cn" source: hosted - version: "1.5.5" + version: "1.7.0" sqflite: dependency: "direct main" description: @@ -293,7 +286,7 @@ packages: name: test_api url: "https://pub.flutter-io.cn" source: hosted - version: "0.2.11" + version: "0.2.15" toggle_rotate: dependency: "direct main" description: @@ -349,7 +342,7 @@ packages: name: xml url: "https://pub.flutter-io.cn" source: hosted - version: "3.5.0" + version: "3.6.1" sdks: dart: ">=2.7.0 <3.0.0" flutter: ">=1.12.13+hotfix.4 <2.0.0"