Browse Source

[New]新增屏幕适配插件

zhipeng 1 year ago
parent
commit
126ee680bb
4 changed files with 84 additions and 58 deletions
  1. 10 0
      lib/main.dart
  2. 63 58
      lib/module/files/view.dart
  3. 8 0
      pubspec.lock
  4. 3 0
      pubspec.yaml

+ 10 - 0
lib/main.dart

@@ -1,6 +1,7 @@
 import 'package:electronic_assistant/resource/string_source.dart';
 import 'package:electronic_assistant/router/app_pages.dart';
 import 'package:flutter/material.dart';
+import 'package:flutter_screenutil/flutter_screenutil.dart';
 import 'package:get/get.dart';
 import 'package:get/get_navigation/src/root/get_material_app.dart';
 
@@ -14,6 +15,15 @@ class MyApp extends StatelessWidget {
   // This widget is the root of your application.
   @override
   Widget build(BuildContext context) {
+    return ScreenUtilInit(
+      designSize: const Size(360, 800),
+      builder: (_, child) {
+        return _buildMaterialApp();
+      },
+    );
+  }
+
+  _buildMaterialApp() {
     return GetMaterialApp(
       title: 'Flutter Demo',
       getPages: AppPage.pages,

+ 63 - 58
lib/module/files/view.dart

@@ -1,6 +1,7 @@
 import 'package:electronic_assistant/base/base_page.dart';
 import 'package:electronic_assistant/module/files/controller.dart';
 import 'package:flutter/material.dart';
+import 'package:flutter_screenutil/flutter_screenutil.dart';
 
 import '../../resource/assets.gen.dart';
 
@@ -9,69 +10,73 @@ class FilesPage extends BasePage<FilesController> {
 
   @override
   Widget? buildBody(BuildContext context) {
-    return Flex(
-      direction: Axis.vertical,
-      children: [
-        Column(
-          children: [
-            AppBar(
-              title: const Text('文件夹'),
-              actions: [
-                IconButton(
-                  onPressed: () {},
-                  icon: ImageIcon(Assets.images.iconFilesNewDir.provider()),
-                ),
-                IconButton(
-                  onPressed: () {},
-                  icon: ImageIcon(Assets.images.iconMore.provider()),
-                ),
-              ],
-            ),
-            Container(
-              height: 36,
-              decoration: BoxDecoration(
-                color: Colors.white,
-                borderRadius: BorderRadius.circular(8),
-              ),
-              child: Flex(
-                direction: Axis.horizontal,
-                children: [
-                  ImageIcon(Assets.images.iconSearch.provider()),
-                  const Expanded(
-                      child: TextField(
-                    decoration: InputDecoration(
-                      hintText: '搜索所有文件标题 / 内容',
-                    ),
-                  ))
+    return Scaffold(
+      body: Flex(
+        direction: Axis.vertical,
+        children: [
+          Column(
+            children: [
+              AppBar(
+                title: const Text('文件夹'),
+                actions: [
+                  IconButton(
+                    onPressed: () {},
+                    icon: ImageIcon(Assets.images.iconFilesNewDir.provider()),
+                  ),
+                  IconButton(
+                    onPressed: () {},
+                    icon: ImageIcon(Assets.images.iconMore.provider()),
+                  ),
                 ],
               ),
-            ),
-          ],
-        ),
-        Expanded(
-            child: NestedScrollView(
-          headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
-            return <Widget>[
-              GridView.builder(
-                gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
-                  crossAxisCount: 2,
+              Container(
+                margin: EdgeInsets.symmetric(horizontal: 12.w),
+                padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 8.w),
+                height: 36.w,
+                decoration: BoxDecoration(
+                  color: Colors.white,
+                  borderRadius: BorderRadius.circular(8.w),
+                ),
+                child: TextField(
+                  maxLines: 1,
+                  textAlignVertical: TextAlignVertical.center,
+                  decoration: InputDecoration(
+                    hintText: '搜索所有文件标题 / 内容',
+                    border: InputBorder.none,
+                    icon: ImageIcon(Assets.images.iconSearch.provider()),
+                    iconColor: const Color.fromRGBO(95, 95, 97, 1),
+                  ),
+                  style: TextStyle(fontSize: 14.sp),
                 ),
-                itemBuilder: (BuildContext context, int index) {
-                  return const SizedBox();
-                },
               ),
-              const Text('全部谈话'),
-            ];
-          },
-          body: AnimatedList(
-            initialItemCount: 10,
-            itemBuilder:
-                (BuildContext context, int index, Animation<double> animation) {
-              return const SizedBox();
-            },
+            ],
           ),
-        ))
-      ],
+          Expanded(
+              child: NestedScrollView(
+            headerSliverBuilder:
+                (BuildContext context, bool innerBoxIsScrolled) {
+              return <Widget>[
+                GridView.builder(
+                  gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
+                    crossAxisCount: 2,
+                  ),
+                  itemBuilder: (BuildContext context, int index) {
+                    return const SizedBox();
+                  },
+                ),
+                const Text('全部谈话'),
+              ];
+            },
+            body: AnimatedList(
+              initialItemCount: 10,
+              itemBuilder: (BuildContext context, int index,
+                  Animation<double> animation) {
+                return const SizedBox();
+              },
+            ),
+          ))
+        ],
+      ),
     );
   }
 }

+ 8 - 0
pubspec.lock

@@ -262,6 +262,14 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "3.0.2"
+  flutter_screenutil:
+    dependency: "direct main"
+    description:
+      name: flutter_screenutil
+      sha256: "8239210dd68bee6b0577aa4a090890342d04a136ce1c81f98ee513fc0ce891de"
+      url: "https://pub.dev"
+    source: hosted
+    version: "5.9.3"
   flutter_test:
     dependency: "direct dev"
     description: flutter

+ 3 - 0
pubspec.yaml

@@ -45,6 +45,9 @@ dependencies:
   # 包信息
   package_info: ^2.0.2
 
+  # 屏幕适配
+  flutter_screenutil: ^5.9.3
+
 dev_dependencies:
   flutter_test:
     sdk: flutter