flutter --画appBar返回键

在这里插入图片描述

appBar: AppBar(

  backgroundColor: Color.fromRGBO(248,250,255,1),  //设置appBar背景色
  elevation: 0, // 立视度为0
  title: Text(
    '记录',
    style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold, ),
  ),
  centerTitle: true, // 居中显示
  leading: Container( // 绘制返回键
    margin: EdgeInsets.all(10), // 设置边距
    decoration: BoxDecoration(
      boxShadow: <BoxShadow>[
        BoxShadow(
          offset: Offset(1, 2), // 阴影起始位置
          blurRadius: 5, // 阴影面积
          color: Colors.grey.withOpacity(.4), // 阴影透明度
        )
      ],
      color: Colors.white, // Container背景色
      borderRadius: BorderRadius.all(
        Radius.circular(100.0), // Container设置为圆形
      ),
    ),
    child: IconButton(
      icon: Icon(
        Icons.arrow_back_ios,
        size: 20,
      ),
      onPressed: () {
        Navigator.pop(context); // 关闭当前页面
      },
    )
  ),
),
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用Flutter中的SystemChrome类来获取设备的屏幕信息,然后通过比较屏幕高度和可视高度的差值来判断设备是否具有虚拟返回。以下是示例代码: ```dart import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; class MyHomePage extends StatefulWidget { MyHomePage({Key key, this.title}) : super(key: key); final String title; @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { bool hasVirtualButton = false; @override void initState() { super.initState(); checkVirtualButton(); } Future<void> checkVirtualButton() async { double screenHeight = MediaQuery.of(context).size.height; double visibleHeight = await SystemChrome.bottomInset; double bottomPadding = MediaQuery.of(context).padding.bottom; double virtualButtonHeight = screenHeight - visibleHeight - bottomPadding; setState(() { hasVirtualButton = virtualButtonHeight > 0; }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: Center( child: Text( hasVirtualButton ? "This device has a virtual button" : "This device doesn't have a virtual button", style: TextStyle(fontSize: 20), ), ), ); } } ``` 在这个示例中,我们使用了 `MediaQuery` 类来获取设备的屏幕信息,然后通过 `SystemChrome.bottomInset` 属性获取设备的可视高度,再通过 `MediaQuery.of(context).padding.bottom` 获取屏幕底部的 padding 值,最后计算出虚拟返回的高度,如果高度大于 0,则说明设备具有虚拟返回

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值