mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
opt.: bio auth setting
This commit is contained in:
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