Skip to content

Commit

Permalink
feat: move UI implement to ap_common_flutter_ui
Browse files Browse the repository at this point in the history
  • Loading branch information
abc873693 committed Oct 8, 2024
1 parent 8cb047f commit 304b60f
Show file tree
Hide file tree
Showing 110 changed files with 801 additions and 2,012 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@

## 套件

| Name | pub.dev | 說明 |
|----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|---------------------|
| `ap_common` | [![ap_common pub.dev badge](https://img.shields.io/pub/v/ap_common.svg?style=flat-square)](https://pub.dev/packages/ap_common/) | 函式庫與相關介面共用 |
| `ap_common_plugin` | [![ap_common pub.dev badge](https://img.shields.io/pub/v/ap_common_plugin.svg?style=flat-square)](https://pub.dev/packages/ap_common_plugin/) | 課表小工具 |
| `ap_common_firebase` | [![ap_common pub.dev badge](https://img.shields.io/pub/v/ap_common_firebase.svg?style=flat-square)](https://pub.dev/packages/ap_common_firebase/) | 服務 `Firebase` 的整合實作 |
| Name | pub.dev | 說明 |
|-------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------|
| `ap_common` | [![ap_common pub.dev badge](https://img.shields.io/pub/v/ap_common.svg?style=flat-square)](https://pub.dev/packages/ap_common/) | 函式庫與相關介面共用 |
| `ap_common_core` | [![ap_common pub.dev badge](https://img.shields.io/pub/v/ap_common.svg?style=flat-square)](https://pub.dev/packages/ap_common_core/) | 純 Dart 的基本類別 |
| `ap_common_flutter_core` | [![ap_common pub.dev badge](https://img.shields.io/pub/v/ap_common_flutter_core.svg?style=flat-square)](https://pub.dev/packages/ap_common_flutter_core/) | 基於 Flutter 框架的核心基本類別 |
| `ap_common_flutter_platform` | [![ap_common pub.dev badge](https://img.shields.io/pub/v/ap_common_flutter_platform.svg?style=flat-square)](https://pub.dev/packages/ap_common_flutter_platform/) | 原生功能實作 |
| `ap_common_flutter_ui` | [![ap_common pub.dev badge](https://img.shields.io/pub/v/ap_common_flutter_ui.svg?style=flat-square)](https://pub.dev/packages/ap_common_flutter_ui/) | UI 實作但不包含原生功能整合 |
| `ap_common_flutter_announcement_ui` | [![ap_common pub.dev badge](https://img.shields.io/pub/v/ap_common_flutter_announcement_ui.svg?style=flat-square)](https://pub.dev/packages/ap_common_flutter_announcement_ui/) | 最新消息服務相關的介面實作 |
| `ap_common_plugin` | [![ap_common pub.dev badge](https://img.shields.io/pub/v/ap_common_plugin.svg?style=flat-square)](https://pub.dev/packages/ap_common_plugin/) | 課表小工具 |
| `ap_common_firebase` | [![ap_common pub.dev badge](https://img.shields.io/pub/v/ap_common_firebase.svg?style=flat-square)](https://pub.dev/packages/ap_common_firebase/) | 服務 `Firebase` 的整合實作 |

## 套件使用要求

- Flutter `v1.20` 以上
- Flutter `v3.22` 以上
10 changes: 5 additions & 5 deletions apps/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ PODS:
- FlutterMacOS
- sign_in_with_apple (0.0.1):
- Flutter
- sqflite (0.0.3):
- sqflite_darwin (0.0.4):
- Flutter
- FlutterMacOS
- url_launcher_ios (0.0.1):
Expand All @@ -81,7 +81,7 @@ DEPENDENCIES:
- share_plus (from `.symlinks/plugins/share_plus/ios`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
- sign_in_with_apple (from `.symlinks/plugins/sign_in_with_apple/ios`)
- sqflite (from `.symlinks/plugins/sqflite/darwin`)
- sqflite_darwin (from `.symlinks/plugins/sqflite_darwin/darwin`)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)

SPEC REPOS:
Expand Down Expand Up @@ -126,8 +126,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"
sign_in_with_apple:
:path: ".symlinks/plugins/sign_in_with_apple/ios"
sqflite:
:path: ".symlinks/plugins/sqflite/darwin"
sqflite_darwin:
:path: ".symlinks/plugins/sqflite_darwin/darwin"
url_launcher_ios:
:path: ".symlinks/plugins/url_launcher_ios/ios"

Expand All @@ -153,7 +153,7 @@ SPEC CHECKSUMS:
share_plus: 8875f4f2500512ea181eef553c3e27dba5135aad
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
sign_in_with_apple: f3bf75217ea4c2c8b91823f225d70230119b8440
sqflite: 673a0e54cc04b7d6dba8d24fb8095b31c3a99eec
sqflite_darwin: a553b1fd6fe66f53bbb0fe5b4f5bab93f08d7a13
url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe

PODFILE CHECKSUM: c9ef12c3fd571f251c0b25e8bb818e50ec70ffe1
Expand Down
12 changes: 4 additions & 8 deletions apps/example/lib/app.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import 'package:ap_common/pages/about_us_page.dart';
import 'package:ap_common/pages/announcement/home_page.dart';
import 'package:ap_common/resources/ap_theme.dart';
import 'package:ap_common/utils/ap_localizations.dart';
import 'package:ap_common/utils/preferences.dart';
import 'package:ap_common/ap_common.dart';
import 'package:ap_common_example/config/constants.dart';
import 'package:ap_common_example/pages/home_page.dart';
import 'package:ap_common_example/utils/app_localizations.dart';
Expand Down Expand Up @@ -36,8 +32,8 @@ class MyAppState extends State<MyApp> with WidgetsBindingObserver {

@override
void initState() {
themeMode = ThemeMode
.values[Preferences.getInt(Constants.PREF_THEME_MODE_INDEX, 0)];
themeMode = ThemeMode.values[
PreferenceUtil.instance.getInt(Constants.PREF_THEME_MODE_INDEX, 0)];
WidgetsBinding.instance.addObserver(this);
Future<void>.microtask(() async {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
Expand Down Expand Up @@ -72,7 +68,7 @@ class MyAppState extends State<MyApp> with WidgetsBindingObserver {
child: MaterialApp(
localeResolutionCallback:
(Locale? locale, Iterable<Locale> supportedLocales) {
final String languageCode = Preferences.getString(
final String languageCode = PreferenceUtil.instance.getString(
Constants.PREF_LANGUAGE_CODE,
ApSupportLanguageConstants.system,
);
Expand Down
16 changes: 9 additions & 7 deletions apps/example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:io';

import 'package:ap_common/resources/ap_icon.dart';
import 'package:ap_common/utils/preferences.dart';
import 'package:ap_common/ap_common.dart';
import 'package:ap_common_example/app.dart';
import 'package:ap_common_example/config/constants.dart';
import 'package:flutter/cupertino.dart';
Expand All @@ -12,13 +11,16 @@ import 'package:google_sign_in_dartio/google_sign_in_dartio.dart';
// ignore_for_file: lines_longer_than_80_chars
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Preferences.init(key: Constants.key, iv: Constants.iv);
registerOneForAll();
await (PreferenceUtil.instance as ApPreferenceUtil)
.init(key: Constants.key, iv: Constants.iv);
if (!kIsWeb && (Platform.isMacOS || Platform.isWindows || Platform.isLinux)) {
GoogleSignInDart.register(
clientId:
'141403473068-9gii2blqbggijifq0ijoqkqv8oj2i2ff.apps.googleusercontent.com',);
clientId:
'141403473068-9gii2blqbggijifq0ijoqkqv8oj2i2ff.apps.googleusercontent.com',
);
}
ApIcon.code =
Preferences.getString(Constants.PREF_ICON_STYLE_CODE, ApIcon.outlined);
ApIcon.code = PreferenceUtil.instance
.getString(Constants.PREF_ICON_STYLE_CODE, ApIcon.outlined);
runApp(const MyApp());
}
7 changes: 1 addition & 6 deletions apps/example/lib/pages/diolog_utils_page.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import 'package:ap_common/models/version_info.dart';
import 'package:ap_common/utils/ap_utils.dart';
import 'package:ap_common/utils/app_tracking_utils.dart';
import 'package:ap_common/utils/dialog_utils.dart';
import 'package:ap_common/utils/notification_utils.dart';
import 'package:ap_common/ap_common.dart';
import 'package:ap_common_example/config/constants.dart';
import 'package:ap_common_example/utils/app_localizations.dart';
import 'package:flutter/material.dart';
Expand All @@ -15,7 +11,6 @@ class DialogUtilsTestPage extends StatefulWidget {
class _DialogUtilsTestPageState extends State<DialogUtilsTestPage> {
late AppLocalizations app;

Day day = NotificationUtils.getDay(DateTime.now().weekday);
TimeOfDay time = TimeOfDay.now();

@override
Expand Down
37 changes: 13 additions & 24 deletions apps/example/lib/pages/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
import 'package:ap_common/api/announcement_helper.dart';
import 'package:ap_common/models/user_info.dart';
import 'package:ap_common/pages/about_us_page.dart';
import 'package:ap_common/pages/announcement/home_page.dart';
import 'package:ap_common/pages/announcement_content_page.dart';
import 'package:ap_common/resources/ap_icon.dart';
import 'package:ap_common/resources/ap_theme.dart';
import 'package:ap_common/scaffold/home_page_scaffold.dart';
import 'package:ap_common/utils/ap_localizations.dart';
import 'package:ap_common/utils/ap_utils.dart';
import 'package:ap_common/utils/notification_utils.dart';
import 'package:ap_common/utils/preferences.dart';
import 'package:ap_common/widgets/ap_drawer.dart';
import 'package:ap_common/ap_common.dart';
import 'package:ap_common_example/config/constants.dart';
import 'package:ap_common_example/pages/diolog_utils_page.dart';
import 'package:ap_common_example/pages/login_page.dart';
Expand Down Expand Up @@ -88,7 +76,7 @@ class HomePageState extends State<HomePage> {
@override
void initState() {
_getAnnouncements();
if (Preferences.getBool(Constants.PREF_AUTO_LOGIN, false)) {
if (PreferenceUtil.instance.getBool(Constants.PREF_AUTO_LOGIN, false)) {
_login();
} else {
checkLogin();
Expand Down Expand Up @@ -126,8 +114,8 @@ class HomePageState extends State<HomePage> {
content: content,
drawer: ApDrawer(
userInfo: userInfo,
displayPicture:
Preferences.getBool(Constants.PREF_DISPLAY_PICTURE, true),
displayPicture: PreferenceUtil.instance
.getBool(Constants.PREF_DISPLAY_PICTURE, true),
imageAsset: drawerIcon,
onTapHeader: () {
if (isLogin) {
Expand Down Expand Up @@ -194,7 +182,7 @@ class HomePageState extends State<HomePage> {
SchoolInfoPage(),
),
),
if (NotificationUtils.isSupport)
if (NotificationUtil.instance.isSupport)
DrawerItem(
icon: ApIcon.dateRange,
title: app.localNotificationTest,
Expand Down Expand Up @@ -228,7 +216,8 @@ class HomePageState extends State<HomePage> {
icon: ApIcon.powerSettingsNew,
title: ap.logout,
onTap: () async {
await Preferences.setBool(Constants.PREF_AUTO_LOGIN, false);
await PreferenceUtil.instance
.setBool(Constants.PREF_AUTO_LOGIN, false);
isLogin = false;
userInfo = null;
content = null;
Expand Down Expand Up @@ -283,7 +272,7 @@ class HomePageState extends State<HomePage> {
break;
}
} else {
ApUtils.showToast(context, ap.notLogin);
UiUtil.instance.showToast(context, ap.notLogin);
}
}

Expand Down Expand Up @@ -337,7 +326,7 @@ class HomePageState extends State<HomePage> {
setState(() {
this.userInfo = userInfo;
});
if (Preferences.getBool(Constants.PREF_DISPLAY_PICTURE, true)) {
if (PreferenceUtil.instance.getBool(Constants.PREF_DISPLAY_PICTURE, true)) {
_getUserPicture();
}
}
Expand All @@ -362,12 +351,12 @@ class HomePageState extends State<HomePage> {

Future<void> _login() async {
await Future<void>.delayed(const Duration(microseconds: 30));
// var username = Preferences.getString(Constants.PREF_USERNAME, '');
// var username = PreferenceUtil.instance.getString(Constants.PREF_USERNAME, '');
// ignore: lines_longer_than_80_chars
// var password = Preferences.getStringSecurity(Constants.PREF_PASSWORD, '');
// var password = PreferenceUtil.instance.getStringSecurity(Constants.PREF_PASSWORD, '');
//to login
isLogin = true;
Preferences.setBool(Constants.PREF_IS_OFFLINE_LOGIN, false);
PreferenceUtil.instance.setBool(Constants.PREF_IS_OFFLINE_LOGIN, false);
_getUserInfo();
if (state != HomeState.finish) {
_getAnnouncements();
Expand Down Expand Up @@ -418,7 +407,7 @@ class HomePageState extends State<HomePage> {
void _openPage(Widget page, {bool needLogin = false}) {
if (!isTablet) Navigator.of(context).pop();
if (needLogin && !isLogin) {
ApUtils.showToast(
UiUtil.instance.showToast(
context,
ApLocalizations.of(context).notLoginHint,
);
Expand Down
53 changes: 27 additions & 26 deletions apps/example/lib/pages/login_page.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import 'package:ap_common/scaffold/login_scaffold.dart';
import 'package:ap_common/utils/ap_localizations.dart';
import 'package:ap_common/utils/ap_utils.dart';
import 'package:ap_common/utils/preferences.dart';
import 'package:ap_common/widgets/progress_dialog.dart';
import 'package:ap_common/ap_common.dart';
import 'package:ap_common_example/config/constants.dart';
import 'package:ap_common_example/res/assets.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -107,7 +103,7 @@ class LoginPageState extends State<LoginPage> {
// setState(() {
// _username.text = username;
// });
// ApUtils.showToast(context, ap.firstLoginHint);
// UiUtil.instance.showToast(context, ap.firstLoginHint);
// }
// },
// )
Expand All @@ -119,8 +115,8 @@ class LoginPageState extends State<LoginPage> {
setState(() {
isRememberPassword = value;
if (!isRememberPassword!) isAutoLogin = false;
Preferences.setBool(Constants.PREF_AUTO_LOGIN, isAutoLogin!);
Preferences.setBool(
PreferenceUtil.instance.setBool(Constants.PREF_AUTO_LOGIN, isAutoLogin!);
PreferenceUtil.instance.setBool(
Constants.PREF_REMEMBER_PASSWORD,
isRememberPassword!,
);
Expand All @@ -131,8 +127,8 @@ class LoginPageState extends State<LoginPage> {
setState(() {
isAutoLogin = value;
isRememberPassword = isAutoLogin;
Preferences.setBool(Constants.PREF_AUTO_LOGIN, isAutoLogin!);
Preferences.setBool(
PreferenceUtil.instance.setBool(Constants.PREF_AUTO_LOGIN, isAutoLogin!);
PreferenceUtil.instance.setBool(
Constants.PREF_REMEMBER_PASSWORD,
isRememberPassword!,
);
Expand All @@ -141,19 +137,22 @@ class LoginPageState extends State<LoginPage> {

Future<void> _getPreference() async {
isRememberPassword =
Preferences.getBool(Constants.PREF_REMEMBER_PASSWORD, true);
isAutoLogin = Preferences.getBool(Constants.PREF_AUTO_LOGIN, false);
PreferenceUtil.instance.getBool(Constants.PREF_REMEMBER_PASSWORD, true);
isAutoLogin =
PreferenceUtil.instance.getBool(Constants.PREF_AUTO_LOGIN, false);
setState(() {
_username.text = Preferences.getString(Constants.PREF_USERNAME, '');
_username.text =
PreferenceUtil.instance.getString(Constants.PREF_USERNAME, '');
_password.text = isRememberPassword!
? Preferences.getStringSecurity(Constants.PREF_PASSWORD, '')
? PreferenceUtil.instance
.getStringSecurity(Constants.PREF_PASSWORD, '')
: '';
});
}

Future<void> _login() async {
if (_username.text.isEmpty || _password.text.isEmpty) {
ApUtils.showToast(context, ap.doNotEmpty, gravity: gravity);
UiUtil.instance.showToast(context, ap.doNotEmpty, gravity: gravity);
} else {
asyncLogin();
}
Expand All @@ -168,36 +167,38 @@ class LoginPageState extends State<LoginPage> {
),
barrierDismissible: false,
);
Preferences.setString(Constants.PREF_USERNAME, _username.text);
PreferenceUtil.instance.setString(Constants.PREF_USERNAME, _username.text);
Navigator.of(context, rootNavigator: true).pop();
Preferences.setString(Constants.PREF_USERNAME, _username.text);
PreferenceUtil.instance.setString(Constants.PREF_USERNAME, _username.text);
if (isRememberPassword!) {
Preferences.setStringSecurity(Constants.PREF_PASSWORD, _password.text);
PreferenceUtil.instance
.setStringSecurity(Constants.PREF_PASSWORD, _password.text);
}
Preferences.setBool(Constants.PREF_IS_OFFLINE_LOGIN, false);
PreferenceUtil.instance.setBool(Constants.PREF_IS_OFFLINE_LOGIN, false);
TextInput.finishAutofillContext();
Navigator.of(context).pop(true);
}

Future<void> _offlineLogin() async {
final String username = Preferences.getString(Constants.PREF_USERNAME, '');
final String username =
PreferenceUtil.instance.getString(Constants.PREF_USERNAME, '');
final String password =
Preferences.getStringSecurity(Constants.PREF_PASSWORD, '');
PreferenceUtil.instance.getStringSecurity(Constants.PREF_PASSWORD, '');
if (username.isEmpty || password.isEmpty) {
ApUtils.showToast(context, ap.noOfflineLoginData);
UiUtil.instance.showToast(context, ap.noOfflineLoginData);
} else {
if (username != _username.text || password != _password.text) {
ApUtils.showToast(context, ap.offlineLoginPasswordError);
UiUtil.instance.showToast(context, ap.offlineLoginPasswordError);
} else {
Preferences.setBool(Constants.PREF_IS_OFFLINE_LOGIN, true);
ApUtils.showToast(context, ap.loadOfflineData);
PreferenceUtil.instance.setBool(Constants.PREF_IS_OFFLINE_LOGIN, true);
UiUtil.instance.showToast(context, ap.loadOfflineData);
Navigator.of(context).pop(true);
}
}
}

Future<void> clearSetting() async {
Preferences.setBool(Constants.PREF_AUTO_LOGIN, false);
PreferenceUtil.instance.setBool(Constants.PREF_AUTO_LOGIN, false);
setState(() {
isAutoLogin = false;
});
Expand Down
Loading

0 comments on commit 304b60f

Please sign in to comment.