flutter dart 小功能记录

单例

class Singleton {
  Singleton._();
  static final instance = Singleton._();
}

AppBar 修改高度

设置AppBar的height

使用PreferredSize:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Example',
      home: Scaffold(
        appBar: PreferredSize(
          preferredSize: Size.fromHeight(50.0), // here the desired height
          child: AppBar(
            // ...
          )
        ),
        body: // ...
      )
    );
  }
}

刷新报错

setState() or markNeedsBuild() called during build

WidgetsBinding.instance.addPostFrameCallback((_){
    _model.setOpacity(opacity);
});

setState() called after dispose()

if (!mounted) return;
setState(() {
  // do somthing
});

相机预览 高度填充

FittedBox(
              fit: BoxFit.fitHeight,
              child: SizedBox(
                width: _controller.value.aspectRatio,
                height: 1,
                child: CameraPreview(_controller),
              ),
            )

Android 下去除滚动波纹动画

NotificationListener<OverscrollIndicatorNotification>(
                  onNotification: (notification) {
                    notification.disallowGlow();
                    return false;
                  },
  child: xxxxx
}

  bool _handleGlowNotification(OverscrollIndicatorNotification notification) {
    if (notification.depth != 0 || !notification.leading) return false;

    notification.disallowGlow();
    return false;
  }

Row/Column 宽度/高度 Wrap_content

    return Column(
      mainAxisSize: MainAxisSize.min,
      children: widgets,
    );

https://stackoverflow.com/questions/42257668/the-equivalent-of-wrap-content-and-match-parent-in-flutter

键盘弹出导致 overflow 处理方法

1. scaffold: resizeToAvoidBottomPadding: false,
2. SingleChildScrollView 包裹 Column

添加图片资源

添加 images 下的所有图片

  assets:
    - assets/images/

Splash 页面跳转问题

使用

Navigator.pushNamedAndRemoveUntil(context, ’/home‘ , (_) => false);

表示跳转到新页面,并且清理之前 router 中的所有历史页面。

计时器

3s 后执行某段代码:

Timer(Duration(seconds: 3), () {
  print("Yeah, this line is printed after 3 seconds");
});

重复执行循环执行:

Timer.periodic(Duration(seconds: 5), (timer) {
  print(DateTime.now());
});
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 7,502评论 0 17
  • 个人学习批处理的初衷来源于实际工作;在某个迭代版本有个BS(安卓手游模拟器)大需求,从而在测试过程中就重复涉及到...
    Luckykailiu阅读 5,053评论 0 11
  • 一、温故而知新 1. 内存不够怎么办 内存简单分配策略的问题地址空间不隔离内存使用效率低程序运行的地址不确定 关于...
    SeanCST阅读 8,188评论 0 27
  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML标准。 注意:讲述HT...
    kismetajun阅读 29,106评论 1 45
  • 今天中午妈妈拿她割好的红纸,还有墨水和毛笔出来教我写对联,妈妈先教我拿毛笔,我刚开始的时候是像拿铅笔一样拿的,后来...
    坠入河畔阅读 509评论 0 2

友情链接更多精彩内容