Skip to content

Commit

Permalink
refactor codes
Browse files Browse the repository at this point in the history
  • Loading branch information
dangfan committed May 6, 2024
1 parent 00f7a20 commit 2c45899
Show file tree
Hide file tree
Showing 78 changed files with 1,031 additions and 3,277 deletions.
6 changes: 2 additions & 4 deletions lib/controller/applets/oath.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:convert';

import 'package:base32/base32.dart';
import 'package:canokey_console/controller/my_controller.dart';
import 'package:canokey_console/controller/base_controller.dart';
import 'package:canokey_console/generated/l10n.dart';
import 'package:canokey_console/helper/theme/admin_theme.dart';
import 'package:canokey_console/helper/tlv.dart';
Expand All @@ -18,7 +18,7 @@ import 'package:timer_controller/timer_controller.dart';

final log = Logger('Console:OATH:Controller');

class OathController extends MyController {
class OathController extends Controller {
final Function(String issuer, String account, String secretHex, OathType type, OathAlgorithm algo, int digits, int initValue) showQrConfirmDialog;
String _codeCache = '';
String _uid = '';
Expand Down Expand Up @@ -277,8 +277,6 @@ class OathController extends MyController {
return;
}
final counter = int.parse(query['counter'] ?? '0');

Navigator.pop(Get.context!);
showQrConfirmDialog(issuer, account, secretHex, type, algo, digits, counter);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/controller/applets/pass.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:canokey_console/controller/my_controller.dart';
import 'package:canokey_console/controller/base_controller.dart';
import 'package:canokey_console/generated/l10n.dart';
import 'package:canokey_console/helper/theme/admin_theme.dart';
import 'package:canokey_console/helper/utils/prompts.dart';
Expand All @@ -12,7 +12,7 @@ import 'package:logging/logging.dart';

final log = Logger('Console:Pass:Controller');

class PassController extends MyController {
class PassController extends Controller {
PassSlot get slotShort => slots[0];

PassSlot get slotLong => slots[1];
Expand Down
8 changes: 4 additions & 4 deletions lib/controller/applets/webauthn.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:canokey_console/controller/my_controller.dart';
import 'package:canokey_console/controller/base_controller.dart';
import 'package:canokey_console/generated/l10n.dart';
import 'package:canokey_console/helper/theme/admin_theme.dart';
import 'package:canokey_console/helper/utils/prompts.dart';
import 'package:canokey_console/helper/utils/smartcard.dart';
import 'package:canokey_console/helper/widgets/my_validators.dart';
import 'package:canokey_console/helper/widgets/validators.dart';
import 'package:canokey_console/models/webauthn.dart';
import 'package:convert/convert.dart';
import 'package:fido2/fido2.dart';
Expand All @@ -15,7 +15,7 @@ import 'package:platform_detector/platform_detector.dart';

final log = Logger('Console:WebAuthn:Controller');

class WebAuthnController extends MyController {
class WebAuthnController extends Controller {
late Ctap2 _ctap;
String _pinCache = '';
String _uid = '';
Expand Down Expand Up @@ -61,7 +61,7 @@ class WebAuthnController extends MyController {
title: S.of(Get.context!).webauthnSetPinTitle,
label: 'PIN',
prompt: S.of(Get.context!).webauthnSetPinPrompt,
validators: [MyLengthValidator(min: 4, max: 63)],
validators: [LengthValidator(min: 4, max: 63)],
);
// On mobile platforms, we need to poll NFC again after showing the dialog
if (isMobile()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:get/get.dart';
import 'package:canokey_console/helper/theme/theme_customizer.dart';

abstract class MyController extends GetxController {
abstract class Controller extends GetxController {
@override
void onInit() {
super.onInit();
Expand Down
4 changes: 2 additions & 2 deletions lib/controller/layout/layout_controller.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:canokey_console/controller/my_controller.dart';
import 'package:canokey_console/controller/base_controller.dart';
import 'package:canokey_console/helper/theme/theme_customizer.dart';
import 'package:flutter/material.dart';

class LayoutController extends MyController {
class LayoutController extends Controller {
ThemeCustomizer themeCustomizer = ThemeCustomizer();

final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey();
Expand Down
4 changes: 2 additions & 2 deletions lib/controller/settings.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:canokey_console/controller/my_controller.dart';
import 'package:canokey_console/controller/base_controller.dart';
import 'package:canokey_console/generated/l10n.dart';
import 'package:canokey_console/helper/theme/admin_theme.dart';
import 'package:canokey_console/helper/utils/prompts.dart';
Expand All @@ -13,7 +13,7 @@ import 'package:logging/logging.dart';

final log = Logger('Console:Settings:Controller');

class SettingsController extends MyController {
class SettingsController extends Controller {
String _uid = '';

late CanoKey key;
Expand Down
4 changes: 2 additions & 2 deletions lib/controller/starter_controller.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import 'package:canokey_console/controller/my_controller.dart';
import 'package:canokey_console/controller/base_controller.dart';

class StarterController extends MyController {}
class StarterController extends Controller {}
15 changes: 1 addition & 14 deletions lib/helper/extensions/date_time_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,7 @@ extension DateTimeExtension on DateTime {
}

String getMonthName({bool short = true}) {
String cMonth = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
][month - 1];
String cMonth = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][month - 1];
return short ? cMonth.substring(0, 3) : cMonth;
}
}
3 changes: 1 addition & 2 deletions lib/helper/extensions/string.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ extension StringUtil on String {
bool toBool([bool defaultValue = false]) {
if (toString().compareTo('1') == 0 || toString().compareTo('true') == 0) {
return true;
} else if (toString().compareTo('0') == 0 ||
toString().compareTo('false') == 0) {
} else if (toString().compareTo('0') == 0 || toString().compareTo('false') == 0) {
return false;
}
return defaultValue;
Expand Down
3 changes: 1 addition & 2 deletions lib/helper/localization/language.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ class Language {

static List<Language> languages = [
Language(Locale('en'), "English"),
Language(
Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans'), "简体中文"),
Language(Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans'), "简体中文"),
];

Language(this.locale, this.languageName);
Expand Down
41 changes: 11 additions & 30 deletions lib/helper/theme/admin_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@ enum ContentThemeColor {
blue;

Color get color {
return (AdminTheme.theme.contentTheme.getMappedIntoThemeColor[this]
?['color']) ??
Colors.black;
return (AdminTheme.theme.contentTheme.getMappedIntoThemeColor[this]?['color']) ?? Colors.black;
}

Color get onColor {
return (AdminTheme.theme.contentTheme.getMappedIntoThemeColor[this]
?['onColor']) ??
Colors.white;
return (AdminTheme.theme.contentTheme.getMappedIntoThemeColor[this]?['onColor']) ?? Colors.white;
}
}

Expand Down Expand Up @@ -77,9 +73,7 @@ class TopBarTheme {

static final TopBarTheme lightTopBarTheme = TopBarTheme();

static final TopBarTheme darkTopBarTheme = TopBarTheme(
background: const Color(0xff2c3036),
onBackground: const Color(0xffdcdcdc));
static final TopBarTheme darkTopBarTheme = TopBarTheme(background: const Color(0xff2c3036), onBackground: const Color(0xffdcdcdc));
}

class ContentTheme {
Expand All @@ -105,10 +99,7 @@ class ContentTheme {
var c = AdminTheme.theme.contentTheme;
return {
ContentThemeColor.primary: {'color': c.primary, 'onColor': c.onPrimary},
ContentThemeColor.secondary: {
'color': c.secondary,
'onColor': c.onSecondary
},
ContentThemeColor.secondary: {'color': c.secondary, 'onColor': c.onSecondary},
ContentThemeColor.success: {'color': c.success, 'onColor': c.onSuccess},
ContentThemeColor.info: {'color': c.info, 'onColor': c.onInfo},
ContentThemeColor.warning: {'color': c.warning, 'onColor': c.onWarning},
Expand Down Expand Up @@ -194,25 +185,15 @@ class AdminTheme {
required this.contentTheme,
});

static AdminTheme theme = AdminTheme(
leftBarTheme: LeftBarTheme.lightLeftBarTheme,
topBarTheme: TopBarTheme.lightTopBarTheme,
contentTheme: ContentTheme.lightContentTheme);
static AdminTheme theme =
AdminTheme(leftBarTheme: LeftBarTheme.lightLeftBarTheme, topBarTheme: TopBarTheme.lightTopBarTheme, contentTheme: ContentTheme.lightContentTheme);

static void setTheme() {
theme = AdminTheme(
leftBarTheme: ThemeCustomizer.instance.theme == ThemeMode.dark
? LeftBarTheme.darkLeftBarTheme
: LeftBarTheme.darkLeftBarTheme,
topBarTheme: ThemeCustomizer.instance.theme == ThemeMode.dark
? TopBarTheme.darkTopBarTheme
: TopBarTheme.lightTopBarTheme,
contentTheme: ThemeCustomizer.instance.theme == ThemeMode.dark
? ContentTheme.darkContentTheme
: ContentTheme.lightContentTheme);

AppTheme.themeType = ThemeCustomizer.instance.theme == ThemeMode.light
? ThemeType.light
: ThemeType.dark;
leftBarTheme: ThemeCustomizer.instance.theme == ThemeMode.dark ? LeftBarTheme.darkLeftBarTheme : LeftBarTheme.darkLeftBarTheme,
topBarTheme: ThemeCustomizer.instance.theme == ThemeMode.dark ? TopBarTheme.darkTopBarTheme : TopBarTheme.lightTopBarTheme,
contentTheme: ThemeCustomizer.instance.theme == ThemeMode.dark ? ContentTheme.darkContentTheme : ContentTheme.lightContentTheme);

AppTheme.themeType = ThemeCustomizer.instance.theme == ThemeMode.light ? ThemeType.light : ThemeType.dark;
}
}
4 changes: 1 addition & 3 deletions lib/helper/theme/app_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ class AppNotifier extends ChangeNotifier {
}

void _changeTheme() {
AppTheme.themeType = ThemeCustomizer.instance.theme == ThemeMode.light
? ThemeType.light
: ThemeType.dark;
AppTheme.themeType = ThemeCustomizer.instance.theme == ThemeMode.light ? ThemeType.light : ThemeType.dark;
AppTheme.theme = AppTheme.getTheme();
}
}
57 changes: 17 additions & 40 deletions lib/helper/theme/app_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ import 'dart:io';
import 'dart:math';

import 'package:canokey_console/helper/theme/admin_theme.dart';
import 'package:canokey_console/helper/widgets/my.dart';
import 'package:canokey_console/helper/widgets/my_constant.dart';
import 'package:canokey_console/helper/widgets/my_text_style.dart';
import 'package:canokey_console/helper/widgets/widgets.dart';
import 'package:canokey_console/helper/widgets/constant.dart';
import 'package:canokey_console/helper/widgets/customized_text_style.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

class MaterialRadius {
double xs, small, medium, large;

MaterialRadius(
{this.xs = 2, this.small = 4, this.medium = 6, this.large = 8});
MaterialRadius({this.xs = 2, this.small = 4, this.medium = 6, this.large = 8});
}

class ColorGroup {
Expand All @@ -28,9 +27,9 @@ class AppStyle {
}

static void initMyStyle() {
MyTextStyle.resetFontStyles();
MyTextStyle.changeFontFamily(GoogleFonts.poppins);
My.setConstant(MyConstantData(
CustomizedTextStyle.resetFontStyles();
CustomizedTextStyle.changeFontFamily(GoogleFonts.poppins);
Widgets.setConstant(WidgetConstantData(
containerRadius: AppStyle.containerRadius.medium,
cardRadius: AppStyle.cardRadius.medium,
buttonRadius: AppStyle.buttonRadius.medium,
Expand All @@ -41,19 +40,15 @@ class AppStyle {
} catch (_) {
isMobile = false;
}
My.setFlexSpacing(isMobile ? 16 : 24);
Widgets.setFlexSpacing(isMobile ? 16 : 24);
}

/// -------------------------- Styles -------------------------------------------- ///
static MaterialRadius buttonRadius =
MaterialRadius(small: 2, medium: 4, large: 8);
static MaterialRadius cardRadius =
MaterialRadius(xs: 2, small: 4, medium: 4, large: 8);
static MaterialRadius containerRadius =
MaterialRadius(xs: 2, small: 4, medium: 4, large: 8);
static MaterialRadius imageRadius =
MaterialRadius(xs: 2, small: 4, medium: 4, large: 8);
static MaterialRadius buttonRadius = MaterialRadius(small: 2, medium: 4, large: 8);
static MaterialRadius cardRadius = MaterialRadius(xs: 2, small: 4, medium: 4, large: 8);
static MaterialRadius containerRadius = MaterialRadius(xs: 2, small: 4, medium: 4, large: 8);
static MaterialRadius imageRadius = MaterialRadius(xs: 2, small: 4, medium: 4, large: 8);
}

class AppColors {
Expand All @@ -69,16 +64,13 @@ class AppColors {
static ColorGroup orange = ColorGroup(Color(0xffFFCEC2), Color(0xffFF3B0A));
static ColorGroup skyBlue = ColorGroup(Color(0xffC2F0FF), Color(0xff0099CC));
static ColorGroup lavender = ColorGroup(Color(0xffEAE2F3), Color(0xff7748AD));
static ColorGroup queenPink =
ColorGroup(Color(0xffE8D9DC), Color(0xff804D57));
static ColorGroup blueViolet =
ColorGroup(Color(0xffC5C6E7), Color(0xff3B3E91));
static ColorGroup queenPink = ColorGroup(Color(0xffE8D9DC), Color(0xff804D57));
static ColorGroup blueViolet = ColorGroup(Color(0xffC5C6E7), Color(0xff3B3E91));
static ColorGroup rosePink = ColorGroup(Color(0xffFCB1E0), Color(0xffEC0999));

static ColorGroup rubinRed = ColorGroup(Color(0x98f6a8bd), Color(0xffd03760));
static ColorGroup favorite = rubinRed;
static ColorGroup redOrange =
ColorGroup(Color(0xffFFAD99), Color(0xffF53100));
static ColorGroup redOrange = ColorGroup(Color(0xffFFAD99), Color(0xffF53100));

static Color notificationSuccessBGColor = Color(0xff117E68);
static Color notificationSuccessTextColor = Color(0xffffffff);
Expand All @@ -90,16 +82,7 @@ class AppColors {

// static Color notificationErrorActionColor = Color(0xff006784);

static List<ColorGroup> list = [
redOrange,
violet,
blue,
green,
orange,
skyBlue,
lavender,
blueViolet
];
static List<ColorGroup> list = [redOrange, violet, blue, green, orange, skyBlue, lavender, blueViolet];

static ColorGroup get random => list[Random().nextInt(list.length)];

Expand All @@ -108,13 +91,7 @@ class AppColors {
}

static Color getColorByRating(int rating) {
var colors = {
1: Color(0xfff0323c),
2: Color(0xcdf0323c),
3: star,
4: Color(0xcd3cd278),
5: Color(0xff3cd278)
};
var colors = {1: Color(0xfff0323c), 2: Color(0xcdf0323c), 3: star, 4: Color(0xcd3cd278), 5: Color(0xff3cd278)};

return colors[rating] ?? colors[1]!;
}
Expand Down
Loading

0 comments on commit 2c45899

Please sign in to comment.