Flutter知识点记录

  • 让安卓和iOS一样push时从右往左


    image.png
  • 下载图片使用占位图

FadeInImage.assetNetwork(
              placeholder: "images/ic_device_image_default.png",
              image: imagePath,
              fit: BoxFit.cover,
 ),
  • 坐标转换 只想获取手势在当前组件中的位置
//1.坐标转换设置key
  GlobalKey indexBarKey = GlobalKey();
//2.在那个需要获取位置的组件设置key,这个组件肯定被手势包着
  key:indexBarKey ,
//3.在手势方法中处理获取坐标
  onVerticalDragDown: (DragDownDetails details){
        RenderBox getBox = indexBarKey.currentContext.findRenderObject();
        Offset local = getBox.globalToLocal(details.globalPosition);
        print(local);
  },
  • 设置电池栏颜色
appBar: AppBar(
    title: Text('123'),
    brightness: Brightness.dark,
),
  • BottomNavigationBar对应页面保持状态的方法
1.with AutomaticKeepAliveClientMixin<>
2.
@override
// TODO: implement wantKeepAlive
 bool get wantKeepAlive => true;
3.builder方法中调用下父类的builder方法
super.build(context);
4.main函数里的Scaffold的body要使用PageView
body:PageView(
   controller: _controller,
   physics: NeverScrollableScrollPhysics(),//禁止首页4个页面的左右滑动
   children: _pages,
),
5. PageView中的controller要初始化
final PageController _controller = PageController();
6.BottomNavigationBar的ontap方法中要切换_controller对应的page
_controller.jumpToPage(index);
  • 创建模型并且在模型中创建字典转模型方法
class HomeModel {
  final String imageUrl;
  final String name;
  final String message;

  HomeModel({this.imageUrl, this.name, this.message});

  //字典Map转模型的构造方法
  factory HomeModel.fromJson(Map jsonMap){
    return HomeModel(imageUrl: jsonMap['imageUrl'],name: jsonMap['name'],message: jsonMap['message']);
  }
}

你可能感兴趣的:(Flutter知识点记录)