Flutter 学习之 statelesswidget 基础

什么是 statelesswidget?

什么是 widget?

在 Flutter 中几乎所有对象都是一个 widget。与原生开发中的控件不同的是,Flutter 中 widget 的概念更广泛,它不仅表示 UI 元素,也可以表示一些功能性组件,如用于手势检测的 GestureDetector Widget…

有哪些方法?

//Widget 类继承自 DiagnosticableTree,DiagnosticableTree 即 诊断树,主要作用是提供调试信息。
abstract class Widget extends DiagnosticableTree {
//key 主要作用是决定下一次创建时是否复用旧的的 Widget。
  const Widget({ this.key });
  final Key? key;
  
  
  //创建 Element
  Element createElement();

  
  String toStringShort() {
    final String type = objectRuntimeType(this, 'Widget');
    return key == null ? type : '$type-$key';
  }

  
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
    properties.defaultDiagnosticsTreeStyle = DiagnosticsTreeStyle.dense;
  }

  
  
  bool operator ==(Object other) => super == other;

  
  
  int get hashCode => super.hashCode;
  static bool canUpdate(Widget oldWidget, Widget newWidget) {
    return oldWidget.runtimeType == newWidget.runtimeType
        && oldWidget.key == newWidget.key;
  }

  static int _debugConcreteSubtype(Widget widget) {
    return widget is StatefulWidget ? 1 :
           widget is StatelessWidget ? 2 :
           0;
  }
}

statelesswidget?

statelesswidget 是 widget 的一个子类,用于无状态的 UI 构建。 它通常在 build 方法中通过嵌套其他 Widget 来构建 UI,在构建过程中会递归构建其嵌套的 Widget。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值