Tips

作者: 周无恋 | 来源:发表于2023-03-12 16:25 被阅读0次

出于性能考虑,ListView.separated每次进入都会加载,因此api要求必须要设置大小,解决方法是

Expanded(
              child:{})

provider状态无改变的时候

Consumer(builder: (
                  BuildContext context,
                  RemindModel value,
                  Widget? child,
                ) {})

Row的平分布局
用 Expanded 包裹 row 里的每个组件:

Row(
  children: [
    Expanded(child: Text()),
    Expanded(child: Text()),
    Expanded(child: Text()),
  ],
)

pub get 后本地的代码没有更新,重新get也不会改变

pub get 后没有更新
  1. 本地的 pubspec.lock 锁定了版本,删除掉, 重新 pub get
  2. 指定 ref 版本

进入app,就设置整个app为竖屏显示

void main() {
  WidgetsFlutterBinding.ensureInitialized(); //不加这个强制横/竖屏会报错
  SystemChrome.setPreferredOrientations([
    // 强制竖屏
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown
  ]);
  runApp(const DemoApp());
}
WidgetsFlutterBinding.ensureInitialized();这行代码一定要写,要不然就报错,而且设置也无效

当进入某个页面时控制横竖屏显示

强制竖屏,代码如下:

    // 强制竖屏
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
      DeviceOrientation.portraitDown
    ]);

强制横屏,代码如下:

   // 强制横屏
   SystemChrome.setPreferredOrientations([
     DeviceOrientation.landscapeLeft,
     DeviceOrientation.landscapeRight
   ]);

退出这个页面时,恢复竖屏显示,代码如下:

  @override
  void dispose() {
    // 强制竖屏
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
      DeviceOrientation.portraitDown
    ]);
    super.dispose();
  }

相关文章

网友评论

      本文标题:Tips

      本文链接:https://www.haomeiwen.com/subject/bhqqrdtx.html