Files
FlutterUnit/lib/views/widgets/StatelessWidget/Builder/node1_base.dart
2020-05-03 23:05:53 +08:00

39 lines
1011 B
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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),
),
),
),
);
}
}