Wrap(
children: <Widget>[your_child])
Container(
height: double.infinity,width: double.infinity,child:your_child)
Row(
mainAxisSize: MainAxisSize.max,children: <Widget>[*your_child*],);
Column(
mainAxisSize: MainAxisSize.max,children: <Widget>[your_child],);
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: httpCall(),builder: (context,snapshot) {
},);
}
class _ExampleState extends State<Example> {
Future<int> future;
@override
void initState() {
future = Future.value(42);
super.initState();
}
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: future,snapshot) {
},);
}
}
Widget _currentBody;
@override
Widget build(BuildContext context) {
return Scaffold(
body: _currentBody,bottomNavigationBar: BottomNavigationBar(
items: <BottomNavigationBarItem>[
...
],onTap: (index) {
_bottomNavigationChange(index);
},),);
}
_bottomNavigationChange(int index) {
switch (index) {
case 0:
_currentBody = OnePage();
break;
case 1:
_currentBody = TwoPage();
break;
case 2:
_currentBody = ThreePage();
break;
}
setState(() {});
}
int _currIndex;
@override
Widget build(BuildContext context) {
return Scaffold(
body: IndexedStack(
index: _currIndex,children: <Widget>[OnePage(),TwoPage(),ThreePage()],);
}
_bottomNavigationChange(int index) {
setState(() {
_currIndex = index;
});
}
TabBarView(
controller: this._tabController,children: <Widget>[
_buildTabView1(),_buildTabView2(),],)
var _newsKey = PageStorageKey('news');
var _technologyKey = PageStorageKey('technology');
TabBarView(
controller: this._tabController,children: <Widget>[
_buildTabView1(_newsKey),_buildTabView2(_technologyKey),)
Center(
child: Container(
height: 300,width: 300,color: Colors.blue,child: Stack(
children: <Widget>[
Positioned.fill(
child: Container(
height: 100,width: 100,color: Colors.red,)
],)
Positioned.fill(
child: Align(
child: Container(
height: 100,)
class Test extends StatefulWidget {
Test({this.data});
final int data;
@override
State<StatefulWidget> createState() => _TestState();
}
class _TestState extends State<Test>{
}
- 在_TestState也定义同样的参数,此方式比较麻烦,不推荐。
- 直接使用
widget.data
(推荐)。
class BarrageItem extends StatefulWidget {
BarrageItem(
{ this.text,this.duration = Duration(seconds: 3)});
const Duration _kDuration = Duration(seconds: 3);
class BarrageItem extends StatefulWidget {
BarrageItem(
{this.text,this.duration = _kDuration});
MaterialApp(
debugShowCheckedModeBanner: false
)
Color(0xb74093)
Color(0xFFb74093)
class _FooState extends State<Foo> {
TextEditingController _controller;
@override
void initState() {
super.initState();
_controller = new TextEditingController(text: '初始值');
}
@override
Widget build(BuildContext context) {
return TextField(
controller: _controller,);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('老孟'),body: Center(
child: RaisedButton(
color: Colors.pink,textColor: Colors.white,onPressed: _displaySnackBar(context),child: Text('show SnackBar'),);
}
}
_displaySnackBar(BuildContext context) {
final snackBar = SnackBar(content: Text('老孟'));
Scaffold.of(context).showSnackBar(snackBar);
}
_scaffoldKey.currentState.showSnackBar(snackbar);
Scaffold(
appBar: AppBar(
title: Text('老孟'),body: Builder(
builder: (context) =>
Center(
child: RaisedButton(
color: Colors.pink,onPressed: () => _displaySnackBar(context),child: Text('老孟'),);
killall -9 dart
taskkill /F /IM dart.exe
MediaQuery.of(context).size.width * 0.5
Row(
children: <Widget>[
Flexible(
child: new TextField(),
FocusScope.of(context).requestFocus(_focusNode);
_focusNode = FocusNode();
TextField(
focusNode: _focusNode,...
)
_focusNode.unfocus();
import 'dart:io' show Platform;
if (Platform.isAndroid) {
// Android-specific code
} else if (Platform.isIOS) {
// iOS-specific code
}
Platform.isAndroid
Platform.isFuchsia
Platform.isIOS
Platform.isLinux
Platform.isMacOS
Platform.isWindows
<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
<application android:networkSecurityConfig="@xml/network_security_config">
<!-- ... -->
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
...
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</plist>