【发布时间】:2019-04-26 11:28:54
【问题描述】:
什么类型的小部件不会有不能改变的状态/属性?我想不出任何可能。按钮有文本,图像有大小,文本有颜色等等。什么小部件不会有某种属性?
在 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'),
);
}
}
【问题讨论】:
-
属性!= 状态。
标签: flutter