semi-xi / blog

blog
4 stars 1 forks source link

flutter #36

Open semi-xi opened 3 years ago

semi-xi commented 3 years ago

override 重写

限制 不确定是不是一样的

final 定义

final wordPair = new WordPair.random();

final不能被重写

脚手架Scaffold

new Scaffold(
      appBar: new AppBar(
        title: new Text('Welcome to Flutter'),
      ),
      body: new Center(
        //child: new Text('Hello World'),
        child: new Text(wordPair.asPascalCase),
      ),
    ),

Widget

Widget 提供一个build方法来显示其他的widget

Widget build(BuildContext context) {
    return  new MaterialApp()
}

StatelessWidget

StatelessWidget 无状态widgt

class MyApp extends StatelessWidget{
}

StatefulWidget

StatefulWidget 有状态类 实现一个有状态部件必须包含2个类

  1. 一个StatefulWidget类
  2. 一个State类,StatefulWidget类本身是不变的,但是State类在widget生命周期中始终存在
// widget
class randomWords extens StatefulWidget {
}

// state
classRandomWordsState extends State<RandomWords> {
   Widget buil(BuildContext context) {
      final wordPair = new WordPair.random();
      return new Text(wordPair.asPascalCase);
   }
}