天天看點

Flutter之Center

1、Center介紹

Center将子控件放在其内部中心,裡面隻能放一個child,但是child裡面可以放Container

Flutter之Center

Center繼承勒Align,然後Align預設是center.

2、測試代碼

測試1、

@override
  Widget build(BuildContext context) {
      return MaterialApp(
          title: 'open url',
          home: Scaffold(
            appBar: AppBar(
              // Here we take the value from the MyHomePage object that was created by
              // the App.build method, and use it to set our appbar title.
              title: Text('hello flutter'),
            ),
            body: Center(
              child: Text("chenyu"),
            ),
          ),
      );
  }
}      

測試2、

@override
  Widget build(BuildContext context) {
      return MaterialApp(
          title: 'open url',
          home: Scaffold(
            appBar: AppBar(
              // Here we take the value from the MyHomePage object that was created by
              // the App.build method, and use it to set our appbar title.
              title: Text('hello flutter'),
            ),
            body: Center(
              child: Container(
                color: Colors.blue,
                width: 200,
                height: 200,
              ),
            ),
          ),
      );
  }
}      

3、運作結果

Flutter之Center
Flutter之Center
Flutter之Center
上一篇: Flutter之Align
下一篇: 雲計算

繼續閱讀