首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么任何小部件都是无状态的?

为什么任何小部件都是无状态的?
EN

Stack Overflow用户
提问于 2019-04-26 19:28:54
回答 2查看 217关注 0票数 0

哪种类型的小部件不会有不能改变的状态/属性?我想不出任何可能的事情。按钮有文本,图像有大小,文本有颜色,等等。什么小部件会没有某种属性呢?

在Flutter演示代码中,"MyApp“是无状态的,但它具有属性。为什么这是无状态的,而不是有状态的?

代码语言:javascript
运行
复制
class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}
EN

Stack Overflow用户

发布于 2019-04-26 21:14:59

有两种状态:

etc...

  • internal状态外部状态:传递给构造函数的变量,,
  • ,etc...
  • internal状态:由此小部件创建的对象。

StatelessWidget是一个没有内部状态的小部件,但它可以使用外部状态。

当参数更改(包括InheritedWidget更新)时,StatelessWidget将正确更新。

票数 1
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55866663

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档