svn项目 不显示绿色钩钩
Flutter Hooks help do away with Stateless and Stateful Widget boiler-plate.
Flutter Hooks有助于消除无状态和有状态的小组件样板。
Here’s an example that sets the hook version of the standard tab controller for tabs by calling the method useTabController(...);
这是设置标准的挂钩版本的示例 选项卡的选项卡控制器 ,方法是调用useTabController(...);
A wee bit of magic sauce,
一小撮魔术酱,
final _key = GlobalKey();
final _key = GlobalKey();
is used by the screen refresh repaint mechanism to identify the TabBarView widget. If you do not give the widget a key, any changes to ${_index.value} will update the Text widgets, but the display repaint will not replace the old Text widgets with their newer refreshed versions, which hold the newly updated _index.value unless a key is set key: _key in TabBarView
屏幕刷新重绘机制使用它来标识TabBarView小部件。 如果您不给窗口小部件一个键,则对${_index.value}任何更改都将更新文本窗口小部件,但是显示重绘不会将旧的文本窗口小部件替换为其较新的刷新版本,这些版本具有新更新的_index.value除非设置了key: _key否则key: _key 中的 TabBarView
import 'package:flutter/material.dart';import 'package:flutter_hooks/flutter_hooks.dart';void main() => runApp(MaterialApp(home: TabBarDemo()));class TabBarDemo extends HookWidget { final List<Widget> list = [ Tab(icon: Icon(Icons.card_travel)), Tab(icon: Icon(Icons.add_shopping_cart)), Tab(icon: Icon(Icons.ac_unit)), ]; @override Widget build(BuildContext context) { final _controller = useTabController(initialLength: list.length); final _index = useState(0); final _key = GlobalKey(); _controller.addListener(() { _index.value = _controller.index; }); return Scaffold( appBar: AppBar( bottom: TabBar( onTap: (index) {}, controller: _controller, tabs: list,), title: Text('Tabs Demo ${_index.value}'), ), body: TabBarView( key: _key, controller: _controller, children: [ Center( child: Text('1.\n_index: ${_index.value}\n_controller.index: ${_controller.index}', style: TextStyle(fontSize: 40),)), Center( child: Text('2.\n_index: ${_index.value}\n_controller.index: ${_controller.index}', style: TextStyle(fontSize: 40),)), Center( child: Text('3.\n_index: ${_index.value}\n_controller.index: ${_controller.index}', style: TextStyle(fontSize: 40),)), ], ), ); }}You can see the complete project on GitHub:
您可以在GitHub看到完整的项目:
Remi Rousselet is the creator of flutter hooks,
Remi Rousselet是颤抖钩的创造者,
To use flutter_hooks add it as a dependency to your project pubspec.yaml file:
要使用flutter_hooks请将其作为依赖flutter_hooks添加到您的项目pubspec.yaml文件中:
dependencies: flutter: sdk: flutter flutter_hooks: anyHere is an article that shows you how to setup a flutter project in a sensible way; it’s also by Rémi Rousselet
这是一篇文章,向您展示如何以明智的方式设置Flutter项目。 这也是RémiRousselet
翻译自: https://medium.com/swlh/hooked-on-flutter-hooks-f56360901963
svn项目 不显示绿色钩钩