哪种类型的小部件不会有不能改变的状态/属性?我想不出任何可能的事情。按钮有文本,图像有大小,文本有颜色,等等。什么小部件会没有某种属性呢?
在Flutter演示代码中,"MyApp“是无状态的,但它具有属性。为什么这是无状态的,而不是有状态的?
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'),
);
}
}发布于 2019-04-26 21:14:59
有两种状态:
etc...
StatelessWidget是一个没有内部状态的小部件,但它可以使用外部状态。
当参数更改(包括InheritedWidget更新)时,StatelessWidget将正确更新。
https://stackoverflow.com/questions/55866663
复制相似问题