【flutter】销毁页面、弹出框、stack定位、GestureDetector点击事件、TextStyle、防止键盘弹出、定时

1、销毁页面

Navigator.of(context).pushAndRemoveUntil(
          MaterialPageRoute(builder: (context) => Biography2()),(route) => route == null);

注意:第二个页面不能设置leading属性的值(左上角防止出现返回按钮)
2、右滑返回上一页案例

在这里插入代码片

3、页面弹出框

1、Tooltip长按提示

class ToolTipDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title:Text('tool tips demo')),
        body:Center(
          child: Tooltip(
            //长按提示
            message: '不要碰我,我怕痒',
            child: Icon(Icons.all_inclusive),
          ),
        )
    );
  }
}

在这里插入图片描述
2、SimpleDialog 弹出层有选择框,并且可以有数据交互

在这里插入图片描述

enum Department {
  treasury,
  state
}

Future<void>  _askedToLead(BuildContext context) async {
  switch (await showDialog<Department>(
    context: context,
    builder: (BuildContext context) {
      return SimpleDialog(
        title: const Text('Select assignment'),
        children: <Widget>[
          SimpleDialogOption(
            onPressed: () {
              Navigator.pop(context, Department.treasury);
            },
            child: const Text('Treasury department'),
          ),
          SimpleDialogOption(
            onPressed: () {
              Navigator.pop(context, Department.state);
            },
            child: const Text('State department'),
          ),
        ],
      );
    },
  )) {
    case Department.treasury:
      print('111');
      break;
    case Department.state:
      print('222');
      break;
  }

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
3、AlertDialog一个会中断用户操作的对话款,需要用户确认
在这里插入图片描述
4、BottomSheet

/**
 * showModalBottomSheet
 */
Future<void> _bottomSheet(BuildContext context) async {
  return showModalBottomSheet(
    context: context,
    builder: (BuildContext context) {
      return new Container(
        height: 300.0,
        //child: new Image.network(.imgurl),
        child : Text("可以使文字,也可以是其他的组件(例如图片)"),
      );
    },
  ).then((val) {
    print(val);//返回值
  });
}

在这里插入图片描述
5、SnackBar

final snackBar = SnackBar(content: Text('这是一个SnackBar!'));
                  Scaffold.of(context).showSnackBar(snackBar);

在这里插入图片描述
4、stack定位,圆弧角

Stack(
            children: <Widget>[
              Column(
                children: <Widget>[
                  Container(
                    height: MediaQuery.of(context).size.height/4,
                    color:  Color.fromARGB(255, 31, 150, 122),
                  ),
                  Container(
                    height: MediaQuery.of(context).size.height*2/4,
                  ),
                ],
              ),
              Positioned(//方法二
                right: MediaQuery.of(context).size.width/(10.0*2),
                top: MediaQuery.of(context).size.height/4-35.0,
                child: ClipRRect(//圆弧角
                  borderRadius: BorderRadius.circular(10.0),
                  child: Container(
                    width: MediaQuery.of(context).size.width*9/10,
                    height: MediaQuery.of(context).size.height/3,
                    color: Colors.black,
                  ),
                )
                /*Text(
                  "鼬",
                  style: TextStyle(fontSize: 40, color: Color(0xFF000000)),
                ),*/
              ),
            ],
          )

在这里插入图片描述
5、GestureDetector点击事件

GestureDetector(
                onTap: (){
                  print('检查记录');
                },
                child: Padding(
                  padding: EdgeInsets.fromLTRB(0, 0, 20.0, 0),
                  child: Text("检查记录",style: TextStyle(fontSize: 20.0),),
                ),
              )

6、Text超出部分显示。。。

Container(
      child: Text("   xxx",style: style,overflow: TextOverflow.ellipsis,),
      padding: EdgeInsets.fromLTRB(20, 15, 10, 0),
    );

7、TextStyle参数

const TextStyle({
    this.inherit: true,         // 为false的时候不显示
    this.color,                    // 颜色 
    this.fontSize,               // 字号
    this.fontWeight,           // 字重,加粗也用这个字段  FontWeight.w700
    this.fontStyle,                // FontStyle.normal  FontStyle.italic斜体
    this.letterSpacing,        // 字符间距  就是单个字母或者汉字之间的间隔,可以是负数
    this.wordSpacing,        // 字间距 句字之间的间距
    this.textBaseline,        // 基线,两个值,字面意思是一个用来排字母的,一人用来排表意字的(类似中文)
    this.height,                // 当用来Text控件上时,行高(会乘以fontSize,所以不以设置过大)
    this.decoration,        // 添加上划线,下划线,删除线 
    this.decorationColor,    // 划线的颜色
    this.decorationStyle,    // 这个style可能控制画实线,虚线,两条线,点, 波浪线等
    this.debugLabel,
    String fontFamily,    // 字体
    String package,
  }) : fontFamily = package == null ? fontFamily : 'packages/$package/$fontFamily',
       assert(inherit != null);

8、flutter 防止键盘弹出 导致超出屏幕

return Scaffold(
resizeToAvoidBottomPadding: false, //输入框抵住键盘
);

9、日期时间插件

flutter_cupertino_date_picker

10、定时

import 'dart:async';

/**
 * 定时测试(可行)
 */
timer(){
  int seconds = 0;
  Timer.periodic(Duration(seconds: 1), (timer) {
    print('计时中...$seconds');
    if(seconds >= 50){
      timer.cancel(); // 取消重复计时
      return;
    }
    seconds++;// 秒数+1
  });
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值