Skip to content

Commit

Permalink
Multi-screen adaptation
Browse files Browse the repository at this point in the history
  • Loading branch information
小滋润 committed Oct 4, 2024
1 parent 74d2845 commit acef024
Show file tree
Hide file tree
Showing 108 changed files with 787 additions and 843 deletions.
2 changes: 1 addition & 1 deletion lib/api/api_server.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dart:async';
import 'dart:collection';
import 'dart:core';
import 'dart:io';
Expand Down Expand Up @@ -129,6 +128,7 @@ class ApiServer {
return ResponseBody({'Msg': '请重新登录'}, isSuccess: false);
} else {
logining = true;
print("ok");
return await Global.navigatorKey.currentState!.pushNamed(UserRoutes.login).then((value) {
logining = false;
if (isShowOverlayLoader) {
Expand Down
71 changes: 44 additions & 27 deletions lib/common/constant.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
part of 'global.dart';

class Constant {
static const double radius = 12.0;
static const double buttomSheetRadius = 28.0;
static const double smallPadding = 8.0;
static const double padding = 16.0;
static const double largePadding = 24.0;
static const double margin = 8.0;
static double radius = 12.0;
static double buttomSheetRadius = 28.0;
static double smallPadding = 8.0;
static double padding = 16.0;
static double largePadding = 24.0;
static double margin = 8.0;

static const double buttomHight = 320;
static const double buttomLetterSpacing = 4.0;
static double buttomHight = 320;
static double buttomLetterSpacing = 4.0;

static const double iconSize = 24;
static const double iconlargeSize = 32;
static const int maxAmount = 99999999; //最大金额为100万减一 存储单位为分
static const int minYear = 2000;
static const int maxYear = 2050;
static double iconSize = 24;
static double iconlargeSize = 32;
static int maxAmount = 99999999; //最大金额为100万减一 存储单位为分
static int minYear = 2000;
static int maxYear = 2050;
static DateTime minDateTime = DateTime(minYear);
static DateTime maxDateTime = DateTime(maxYear);

static String defultLocation = 'Asia/Shanghai';
static init() {
radius = 12.0.sp;
buttomSheetRadius = 28.0.sp;
smallPadding = 8.0.sp;
padding = 16.0.sp;
largePadding = 24.0.sp;
margin = 8.0.sp;
buttomHight = 320.0.h;
buttomLetterSpacing = 4.0.sp;
}
}

class ConstantFontSize {
Expand All @@ -32,43 +42,50 @@ class ConstantFontSize {
static const double bodySmall = 12;

static const double letterSpacing = 2;
// static init() {
// largeHeadline = largeHeadline.sp;
// headline = headline.sp;
// bodyLarge = bodyLarge.sp;
// body = body.sp;
// bodySmall = bodySmall.sp;
// letterSpacing = letterSpacing.sp;
// }
}

class ConstantWidget {
// ignore: library_private_types_in_public_api
static const _ConstantWidgetDivider divider = _ConstantWidgetDivider();
static _ConstantWidgetDivider divider = _ConstantWidgetDivider();
static const Widget activityIndicator = CircularProgressIndicator();
}

class ConstantDecoration {
static const Radius radius = Radius.circular(Constant.radius);
static const BorderRadius borderRadius = BorderRadius.all(Radius.circular(Constant.radius));
static const BorderRadius bottomSheetBorderRadius =
BorderRadius.vertical(top: Radius.circular(Constant.buttomSheetRadius));
static Radius radius = Radius.circular(Constant.radius);
static BorderRadius borderRadius = BorderRadius.all(Radius.circular(Constant.radius));
static BorderRadius bottomSheetBorderRadius = BorderRadius.vertical(top: Radius.circular(Constant.buttomSheetRadius));
//BoxDecoration
static const BoxDecoration cardDecoration = BoxDecoration(
static BoxDecoration cardDecoration = BoxDecoration(
color: Colors.white,
borderRadius: ConstantDecoration.borderRadius,
);
static const BoxDecoration bottomSheet = BoxDecoration(
static BoxDecoration bottomSheet = BoxDecoration(
color: Colors.white,
borderRadius: bottomSheetBorderRadius,
);
}

class _ConstantWidgetDivider {
const _ConstantWidgetDivider();
final Divider list = const Divider(
_ConstantWidgetDivider();
final Divider list = Divider(
color: ConstantColor.listDividerColor,
height: 0.5,
thickness: 0.5,
height: 0.5.sp,
thickness: 0.5.sp,
);
final Divider indented = const Divider(
final Divider indented = Divider(
color: ConstantColor.listDividerColor,
indent: Constant.margin,
endIndent: Constant.margin,
height: 0.5,
thickness: 0.5,
height: 0.5.sp,
thickness: 0.5.sp,
);
}

Expand Down
1 change: 1 addition & 0 deletions lib/common/global.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:leap_ledger_app/model/account/model.dart';
import 'package:leap_ledger_app/routes/routes.dart';
import 'package:leap_ledger_app/util/enter.dart';
import 'package:path_provider/path_provider.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

part 'constant.dart';
part 'no_data.dart';
Expand Down
148 changes: 81 additions & 67 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:intl/intl.dart';
import 'package:leap_ledger_app/bloc/account/account_bloc.dart';
import 'package:leap_ledger_app/bloc/category/category_bloc.dart';
Expand All @@ -14,15 +13,21 @@ import 'package:leap_ledger_app/view/navigation/navigation.dart';
import 'common/global.dart';
import 'package:leap_ledger_app/common/current.dart';
import 'package:timezone/data/latest_all.dart' as tzData;
import 'package:flutter_screenutil/flutter_screenutil.dart';

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
init().then((e) => runApp(MyApp()));
}

Future<void> init() async {
WidgetsFlutterBinding.ensureInitialized();
//ScreenUtil
await ScreenUtil.ensureScreenSize();
//TimeZones
tzData.initializeTimeZones();
//SharedPreferencesCache
await SharedPreferencesCache.init();
//config
await Global.init();
await Current.init();
//await Global.cache.clear();
Expand All @@ -39,6 +44,8 @@ class MyApp extends StatelessWidget {
final AccountBloc _accountBloc = AccountBloc();
@override
Widget build(BuildContext context) {
ScreenUtil.init(context);

return MultiRepositoryProvider(
providers: [
RepositoryProvider<UserBloc>(create: (context) => UserBloc(_accountBloc)),
Expand All @@ -47,73 +54,80 @@ class MyApp extends StatelessWidget {
RepositoryProvider<TransactionBloc>(create: (context) => TransactionBloc()),
RepositoryProvider<CategoryBloc>(create: (context) => CategoryBloc()),
],
child: MaterialApp(
supportedLocales: const [
Locale('zh', 'CN'),
],
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
localeResolutionCallback: (locale, supportedLocales) {
for (var supportedLocale in supportedLocales) {
if (supportedLocale.languageCode == locale?.languageCode &&
supportedLocale.countryCode == locale?.countryCode) {
Intl.defaultLocale = supportedLocale.languageCode;
return supportedLocale;
}
}
Intl.defaultLocale = supportedLocales.first.languageCode;
return supportedLocales.first;
},
navigatorKey: Global.navigatorKey,
title: 'Flutter Demo',
theme: ThemeData(
tabBarTheme: const TabBarTheme(
dividerHeight: 0,
overlayColor: WidgetStatePropertyAll<Color>(
Colors.white,
),
),
colorScheme: const ColorScheme.light(
primary: ConstantColor.primaryColor,
secondary: ConstantColor.secondaryColor,
),
primaryColor: ConstantColor.primaryColor,
dividerColor: Colors.transparent,
appBarTheme: AppBarTheme(
color: Colors.white,
shadowColor: ConstantColor.shadowColor,
surfaceTintColor: Colors.white,
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ButtonStyle(
backgroundColor: WidgetStatePropertyAll(Colors.blue),
foregroundColor: WidgetStatePropertyAll(Colors.white),
child: ScreenUtilInit(
designSize: const Size(375, 667),
minTextAdapt: true,
splitScreenMode: true,
builder: (context, child) {
return MaterialApp(
debugShowCheckedModeBanner: false,
supportedLocales: const [
Locale('zh', 'CN'),
],
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
localeResolutionCallback: (locale, supportedLocales) {
for (var supportedLocale in supportedLocales) {
if (supportedLocale.languageCode == locale?.languageCode &&
supportedLocale.countryCode == locale?.countryCode) {
Intl.defaultLocale = supportedLocale.languageCode;
return supportedLocale;
}
}
Intl.defaultLocale = supportedLocales.first.languageCode;
return supportedLocales.first;
},
navigatorKey: Global.navigatorKey,
theme: ThemeData(
tabBarTheme: TabBarTheme(
dividerHeight: 0,
overlayColor: WidgetStatePropertyAll<Color>(Colors.white),
),
colorScheme: const ColorScheme.light(
primary: ConstantColor.primaryColor,
secondary: ConstantColor.secondaryColor,
),
primaryColor: ConstantColor.primaryColor,
dividerColor: Colors.transparent,
appBarTheme: AppBarTheme(
color: Colors.white,
shadowColor: ConstantColor.shadowColor,
surfaceTintColor: Colors.white,
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ButtonStyle(
backgroundColor: WidgetStatePropertyAll(Colors.blue),
foregroundColor: WidgetStatePropertyAll(Colors.white),
),
),
floatingActionButtonTheme: const FloatingActionButtonThemeData(
backgroundColor: Colors.blue,
shape: CircleBorder(),
// smallSizeConstraints: BoxConstraints(minWidth: 100),
// extendedSizeConstraints: BoxConstraints(minWidth: 100),
),
bottomSheetTheme: const BottomSheetThemeData(
backgroundColor: Colors.white,
surfaceTintColor: Colors.white,
),
iconTheme: IconThemeData.fallback().copyWith(applyTextScaling: true),
useMaterial3: true,
),
),
floatingActionButtonTheme: const FloatingActionButtonThemeData(
backgroundColor: Colors.blue,
shape: CircleBorder(),
// smallSizeConstraints: BoxConstraints(minWidth: 100),
// extendedSizeConstraints: BoxConstraints(minWidth: 100),
),
bottomSheetTheme: const BottomSheetThemeData(
backgroundColor: Colors.white,
surfaceTintColor: Colors.white,
),
useMaterial3: true,
),
home: Navigation(),
builder: EasyLoading.init(builder: (context, child) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaler: TextScaler.noScaling),
child: child!,
home: Navigation(),
builder: (context, widget) {
Constant.init();
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaler: TextScaler.linear(1.sp)),
child: widget!,
);
},
routes: Routes.routes,
onGenerateRoute: Routes.generateRoute,
);
}),
routes: Routes.routes,
onGenerateRoute: Routes.generateRoute,
},
));
}
}
2 changes: 2 additions & 0 deletions lib/model/user/model.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:leap_ledger_app/common/global.dart';
import 'package:leap_ledger_app/model/account/model.dart';
import 'package:leap_ledger_app/util/enter.dart';
import 'package:leap_ledger_app/widget/common/common.dart';
Expand Down
4 changes: 2 additions & 2 deletions lib/model/user/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class UserInfoModel {
username = other.username;

Widget get avatarPainterWidget => SizedBox(
width: 50,
height: 50,
width: 50.sp,
height: 50.sp,
child: CustomPaint(painter: CommonAvatarPainter(username: username)),
);

Expand Down
1 change: 1 addition & 0 deletions lib/util/enter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:convert';
import 'dart:async';

import 'package:file_picker/file_picker.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:leap_ledger_app/common/global.dart';
import 'package:permission_handler/permission_handler.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/util/toast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class Toast {
timeInSecForIosWeb: 5,
backgroundColor: Colors.black45,
textColor: Colors.white,
fontSize: 16.0);
fontSize: ConstantFontSize.bodyLarge);
}
}
Loading

0 comments on commit acef024

Please sign in to comment.