mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-18 07:44:26 +01:00
opt.: bio auth setting
This commit is contained in:
@@ -6,7 +6,9 @@ import 'package:toolbox/core/extension/context/common.dart';
|
||||
import 'package:toolbox/core/extension/context/dialog.dart';
|
||||
import 'package:toolbox/core/extension/context/locale.dart';
|
||||
import 'package:toolbox/core/extension/context/snackbar.dart';
|
||||
import 'package:toolbox/core/utils/platform/auth.dart';
|
||||
import 'package:toolbox/data/res/store.dart';
|
||||
import 'package:toolbox/view/page/setting/platform_pub.dart';
|
||||
import 'package:toolbox/view/widget/custom_appbar.dart';
|
||||
import 'package:toolbox/view/widget/input_field.dart';
|
||||
import 'package:toolbox/view/widget/round_rect_card.dart';
|
||||
@@ -39,6 +41,8 @@ class _AndroidSettingsPageState extends State<AndroidSettingsPage> {
|
||||
children: [
|
||||
_buildBgRun(),
|
||||
_buildAndroidWidgetSharedPreference(),
|
||||
if (BioAuth.isPlatformSupported)
|
||||
PlatformPublicSettings.buildBioAuth(),
|
||||
].map((e) => RoundRectCard(e)).toList(),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -11,7 +11,6 @@ import 'package:toolbox/core/extension/context/snackbar.dart';
|
||||
import 'package:toolbox/core/extension/locale.dart';
|
||||
import 'package:toolbox/core/extension/context/dialog.dart';
|
||||
import 'package:toolbox/core/extension/stringx.dart';
|
||||
import 'package:toolbox/core/utils/platform/auth.dart';
|
||||
import 'package:toolbox/core/utils/platform/base.dart';
|
||||
import 'package:toolbox/core/utils/rebuild.dart';
|
||||
import 'package:toolbox/data/res/provider.dart';
|
||||
@@ -29,7 +28,6 @@ import '../../../data/res/path.dart';
|
||||
import '../../../data/res/ui.dart';
|
||||
import '../../widget/color_picker.dart';
|
||||
import '../../widget/custom_appbar.dart';
|
||||
import '../../widget/future_widget.dart';
|
||||
import '../../widget/input_field.dart';
|
||||
import '../../widget/round_rect_card.dart';
|
||||
import '../../widget/store_switch.dart';
|
||||
@@ -187,9 +185,6 @@ class _SettingPageState extends State<SettingPage> {
|
||||
//_buildLaunchPage(),
|
||||
_buildCheckUpdate(),
|
||||
];
|
||||
if (BioAuth.isPlatformSupported) {
|
||||
children.add(_buildBioAuth());
|
||||
}
|
||||
|
||||
/// Platform specific settings
|
||||
if (OS.hasSettings) {
|
||||
@@ -1014,47 +1009,6 @@ class _SettingPageState extends State<SettingPage> {
|
||||
// );
|
||||
// }
|
||||
|
||||
Widget _buildBioAuth() {
|
||||
return FutureWidget<bool>(
|
||||
future: BioAuth.isAvail,
|
||||
loading: ListTile(
|
||||
title: Text(l10n.bioAuth),
|
||||
subtitle: Text(l10n.serverTabLoading, style: UIs.textGrey),
|
||||
),
|
||||
error: (e, __) => ListTile(
|
||||
title: Text(l10n.bioAuth),
|
||||
subtitle: Text('${l10n.failed}: $e', style: UIs.textGrey),
|
||||
),
|
||||
success: (can) {
|
||||
return ListTile(
|
||||
title: Text(l10n.bioAuth),
|
||||
subtitle: can
|
||||
? null
|
||||
: const Text('Error: Bio auth is not available',
|
||||
style: UIs.textGrey),
|
||||
trailing: can
|
||||
? StoreSwitch(
|
||||
prop: Stores.setting.useBioAuth,
|
||||
func: (val) async {
|
||||
if (val) {
|
||||
Stores.setting.useBioAuth.put(false);
|
||||
return;
|
||||
}
|
||||
// Only auth when turn off (val == false)
|
||||
final result = await BioAuth.auth(l10n.authRequired);
|
||||
// If failed, turn on again
|
||||
if (result != AuthResult.success) {
|
||||
Stores.setting.useBioAuth.put(true);
|
||||
}
|
||||
},
|
||||
)
|
||||
: null,
|
||||
);
|
||||
},
|
||||
noData: UIs.placeholder,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPlatformSetting() {
|
||||
return ListTile(
|
||||
title: Text('${OS.type} ${l10n.setting}'),
|
||||
|
||||
@@ -6,10 +6,12 @@ import 'package:toolbox/core/extension/context/locale.dart';
|
||||
import 'package:toolbox/core/extension/context/snackbar.dart';
|
||||
import 'package:toolbox/core/route.dart';
|
||||
import 'package:toolbox/core/utils/misc.dart';
|
||||
import 'package:toolbox/core/utils/platform/auth.dart';
|
||||
import 'package:toolbox/data/res/logger.dart';
|
||||
import 'package:toolbox/data/res/misc.dart';
|
||||
import 'package:toolbox/data/res/store.dart';
|
||||
import 'package:toolbox/data/res/ui.dart';
|
||||
import 'package:toolbox/view/page/setting/platform_pub.dart';
|
||||
import 'package:toolbox/view/widget/custom_appbar.dart';
|
||||
import 'package:toolbox/view/widget/future_widget.dart';
|
||||
import 'package:toolbox/view/widget/round_rect_card.dart';
|
||||
@@ -40,6 +42,8 @@ class _IOSSettingsPageState extends State<IOSSettingsPage> {
|
||||
_buildPushToken(),
|
||||
_buildAutoUpdateHomeWidget(),
|
||||
_buildWatchApp(),
|
||||
if (BioAuth.isPlatformSupported)
|
||||
PlatformPublicSettings.buildBioAuth(),
|
||||
].map((e) => RoundRectCard(e)).toList(),
|
||||
),
|
||||
);
|
||||
|
||||
52
lib/view/page/setting/platform_pub.dart
Normal file
52
lib/view/page/setting/platform_pub.dart
Normal file
@@ -0,0 +1,52 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:toolbox/core/extension/context/locale.dart';
|
||||
import 'package:toolbox/core/utils/platform/auth.dart';
|
||||
import 'package:toolbox/data/res/store.dart';
|
||||
import 'package:toolbox/data/res/ui.dart';
|
||||
import 'package:toolbox/view/widget/future_widget.dart';
|
||||
import 'package:toolbox/view/widget/store_switch.dart';
|
||||
|
||||
class PlatformPublicSettings {
|
||||
static Widget buildBioAuth() {
|
||||
return FutureWidget<bool>(
|
||||
future: BioAuth.isAvail,
|
||||
loading: ListTile(
|
||||
title: Text(l10n.bioAuth),
|
||||
subtitle: Text(l10n.serverTabLoading, style: UIs.textGrey),
|
||||
),
|
||||
error: (e, __) => ListTile(
|
||||
title: Text(l10n.bioAuth),
|
||||
subtitle: Text('${l10n.failed}: $e', style: UIs.textGrey),
|
||||
),
|
||||
success: (can) {
|
||||
return can
|
||||
? ListTile(
|
||||
title: Text(l10n.bioAuth),
|
||||
subtitle: can
|
||||
? null
|
||||
: const Text('Error: Bio auth is not available',
|
||||
style: UIs.textGrey),
|
||||
trailing: can
|
||||
? StoreSwitch(
|
||||
prop: Stores.setting.useBioAuth,
|
||||
func: (val) async {
|
||||
if (val) {
|
||||
Stores.setting.useBioAuth.put(false);
|
||||
return;
|
||||
}
|
||||
// Only auth when turn off (val == false)
|
||||
final result = await BioAuth.auth(l10n.authRequired);
|
||||
// If failed, turn on again
|
||||
if (result != AuthResult.success) {
|
||||
Stores.setting.useBioAuth.put(true);
|
||||
}
|
||||
},
|
||||
)
|
||||
: null,
|
||||
)
|
||||
: UIs.placeholder;
|
||||
},
|
||||
noData: UIs.placeholder,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user