Files
2022-04-01 20:37:44 +08:00

34 lines
1.5 KiB
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/9/21
/// contact me by email 1981462002@qq.com
/// 说明: 243 UniqueWidget 唯一组件
/// 抽象类,必须提供一个 GlobalKey 进行身份标识,该类型组件只会 inflated 一个实例,同一时刻也只会有一个状态,可以通过 currentState 属性获取状态。
///
// {
// "widgetId": 243,
// "name": 'UniqueWidget 介绍',
// "priority": 1,
// "subtitle": "【child】 : 子组件 【Widget】",
// }
class UniqueWidgetDemo extends StatelessWidget {
const UniqueWidgetDemo({Key? key}) : super(key: key);
final String info =
'该类是抽象类,在 Flutter 框架层没有实现类,也没有其他源码使用到它,说明它基本上没啥用。'
'本质上它也非常简单,就是为组件添加一个 GlobalKey在 Element#inflateWidget 时,会校验组件是否有 GlobalKey '
'如果有,则根据 key 找到之前的对应的 Element就不会触发 Widget#createElement。为了方便获取 State该类暴露 currentState 属性。'
'你瞄一下源码,就能看到这个组件是多么简单,简单到可以自己完成,以至于没什么大用。';
@override
Widget build(BuildContext context) {
return Container(
color: Colors.blue.withOpacity(0.1),
padding: const EdgeInsets.all(10),
margin: const EdgeInsets.all(10),
child: Text(info),
);
}
}