Flutter采坑笔记

1.所有弹出窗口所使用的context不能是顶层Widget的context,同时顶层Widget必须是StatefulWidget。参考:https://www.jianshu.com/p/4c099e8c03c0
2.Button设置宽高的方法

Row(
  children: [
    Expanded(
      child: FlatButton(
        color: Theme.of(context).buttonColor,
        child: Padding(
           padding: EdgeInsets.fromLTRB(0, 15, 0, 15),
              child: Text("立即支付"),
           ),
        shape: StadiumBorder(side: BorderSide.none),
        onPressed: () {},
      ),
    ),
  ]
)

3.button通过shape属性设置样式

//统一四边颜色和宽度
shape: Border.all(color: Color(0xFF00FFFF),style: BorderStyle.solid,width: 2)
四个边分别指定颜色和宽度, 当只给bottom时与UnderlineInputBorder一致效果
shape: Border(top: b, bottom: b, right: b, left: b)
// 底部线
shape: UnderlineInputBorder( borderSide:BorderSide(color: Color(0xFFFFFFFF), style: BorderStyle.solid, width: 2))
// 矩形边色
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(10)), side: BorderSide(color: Color(0xFFFFFFFF), style: BorderStyle.solid, width: 2))
// 圆形边色
shape: CircleBorder(side: BorderSide(color: Color(0xFFFFFF00), style: BorderStyle.solid, width: 2))
// 体育场(竖向椭圆)
shape: StadiumBorder(side: BorderSide(width: 2, style: BorderStyle.solid, color: Color(0xFF00FFFF)))
// 角形(八边角)边色
shape: BeveledRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(10)), side: BorderSide(color: Color(0xFFFFFFFF), style: BorderStyle.solid, width: 2))

4.Flutter1.0版本UIKitView嵌入原生View需要在Xcode工程info.plist添加io.flutter.embedded_views_preview为true。
5.打开和关闭Drawer

Scaffold.of(context).openDrawer();
Navigator.pop;

6.监听bottomSheet关闭

void _showModal() {
    Future future = showModalBottomSheet(
      context: context,
      builder: (BuildContext context) {
        return Container(height: 260.0, child: Text('I am text'));
      },
    );
    future.then((void value) => _closeModal(value));
}
void _closeModal(void value) {
    print('modal closed');
}

7.自定义AppBar
https://stackoverflow.com/questions/48121864/how-to-make-custom-appbar-in-flutter-like-in-hamilton-flutter-app
8.设置AppBar阴影高度

appBar: new AppBar(
    title: new Text('My App Title'),
    elevation: 0.0,
)

9.Text文本换行溢出
https://stackoverflow.com/questions/54634093/flutter-wrap-text-instead-of-overflow?r=SearchResults

你可能感兴趣的:(Flutter采坑笔记)