fluter 学习笔记

98 阅读1分钟

fluter 用于开发app适配

import 'package:flutter_screenutil/flutter_screenutil.dart';

class ScreenAdapter{

  static width(num v){
    return v.w;
  }
  static height(num v){
    return v.h;
  }
  static fontSize(num v){
    return v.sp;
  }
  static getScreenWidth(){
    // return  ScreenUtil().screenWidth;
    return 1.sw;
  }
  static getScreenHeight  (){
    // return  ScreenUtil().screenHeight;
    return 1.sh;
  }

}

然后再mian里1引入 全局配置

import 'package:flutter_screenutil/flutter_screenutil.dart';
void main() {
  runApp(
    ScreenUtilInit(
      designSize: const Size(375, 812), // 设计稿尺寸
      minTextAdapt: true,
      splitScreenMode: true,
        builder:( context,child){
            return  GetMaterialApp(
              debugShowCheckedModeBanner: false,
              title: "Application",
              initialRoute: AppPages.INITIAL,
              getPages: AppPages.routes,
              theme: ThemeData(
                splashColor: Colors.transparent,
                highlightColor: Colors.transparent,
              ),
            );
        }
    )
  );
}

在页面中使用

import '../../../../utils/Adapter.dart';
appBar: AppBar(
  title:  Text('HomeView' , style: TextStyle(fontSize: ScreenAdapter.fontSize(12)),),
  centerTitle: true,
),

今天的学习分享就到这里啦