|
|
|
|
@ -1,3 +1,5 @@
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_advanced_switch/flutter_advanced_switch.dart';
|
|
|
|
|
import 'package:local_auth/local_auth.dart';
|
|
|
|
|
@ -24,16 +26,44 @@ class _SettingsPageState extends State<SettingsPage> {
|
|
|
|
|
ValueNotifier<bool> langController, themeController;
|
|
|
|
|
SettingProvider _settingProvider;
|
|
|
|
|
|
|
|
|
|
bool localAuth = false;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
// TODO: implement initState
|
|
|
|
|
super.initState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
super.dispose();
|
|
|
|
|
langController.dispose();
|
|
|
|
|
themeController.dispose();
|
|
|
|
|
// authController.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void checkForLocalAuth(bool buttonState) async {
|
|
|
|
|
bool authStatus = await _settingProvider.auth.authenticate(
|
|
|
|
|
localizedReason: Platform.isAndroid ? "Scan your fingerprint to authenticate" : "",
|
|
|
|
|
options: AuthenticationOptions(biometricOnly: Platform.isAndroid),
|
|
|
|
|
);
|
|
|
|
|
if (authStatus) {
|
|
|
|
|
localAuth = !localAuth;
|
|
|
|
|
await _settingProvider.setAuth(localAuth);
|
|
|
|
|
// authController.value = _settingProvider.localAuth == buttonState.toString();
|
|
|
|
|
setState(() {});
|
|
|
|
|
} else {
|
|
|
|
|
// authController.value = !buttonState;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
_settingProvider ??= Provider.of<SettingProvider>(context, listen: false);
|
|
|
|
|
if (_settingProvider == null) {
|
|
|
|
|
_settingProvider = Provider.of<SettingProvider>(context, listen: false);
|
|
|
|
|
localAuth = _settingProvider.localAuth;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
langController ??= ValueNotifier<bool>(_settingProvider.language == "ar")
|
|
|
|
|
..addListener(() async {
|
|
|
|
|
/// TODO : uncomment the below lines to support the another language
|
|
|
|
|
@ -45,17 +75,18 @@ class _SettingsPageState extends State<SettingsPage> {
|
|
|
|
|
await _settingProvider.setDarkTheme(_settingProvider.theme == "light");
|
|
|
|
|
themeController.value = _settingProvider.theme == "light";
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// authController ??= ValueNotifier<bool>(_settingProvider.localAuth == "false")
|
|
|
|
|
// ..addListener(() async {
|
|
|
|
|
// print("authController.value:${authController.value}");
|
|
|
|
|
//
|
|
|
|
|
// _settingProvider.auth.getAvailableBiometrics().then((value) {
|
|
|
|
|
// value.forEach((element) => print(element.name));
|
|
|
|
|
// print("face:${value.contains(BiometricType.face)}");
|
|
|
|
|
// print("bio:${value.contains(BiometricType.fingerprint)}");
|
|
|
|
|
// print("iris:${value.contains(BiometricType.iris)}");
|
|
|
|
|
// print("weak:${value.contains(BiometricType.weak)}");
|
|
|
|
|
// print("strong:${value.contains(BiometricType.strong)}");
|
|
|
|
|
//
|
|
|
|
|
// _settingProvider.auth.canCheckBiometrics.then((value) => print(value));
|
|
|
|
|
// });
|
|
|
|
|
// // if (authController.value) {
|
|
|
|
|
// // checkForLocalAuth();
|
|
|
|
|
// // } else {
|
|
|
|
|
// // await _settingProvider.setAuth(_settingProvider.localAuth == "false");
|
|
|
|
|
// // authController.value = _settingProvider.localAuth == "false";
|
|
|
|
|
// // }
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: DefaultAppBar(title: context.translation.settings),
|
|
|
|
|
@ -100,40 +131,50 @@ class _SettingsPageState extends State<SettingsPage> {
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
// 16.height,
|
|
|
|
|
// const Divider().defaultStyle(context),
|
|
|
|
|
// 16.height,
|
|
|
|
|
// FutureBuilder(
|
|
|
|
|
// future: _settingProvider.auth.isDeviceSupported(),
|
|
|
|
|
// builder: (cxt, snapshot) {
|
|
|
|
|
// bool isDeviceSupported = false;
|
|
|
|
|
// if (snapshot.hasData) {
|
|
|
|
|
// isDeviceSupported = snapshot.data;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (!isDeviceSupported) {
|
|
|
|
|
// return Text("Your device did not support Fingerprint/Face ID.", style: AppTextStyles.tinyFont.copyWith(fontSize: 11, color: Colors.red));
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// return Row(
|
|
|
|
|
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
// children: [
|
|
|
|
|
// context.translation.lightTheme.heading5(context),
|
|
|
|
|
// AdvancedSwitch(
|
|
|
|
|
// controller: themeController,
|
|
|
|
|
// activeColor: AppColor.green50.withOpacity(0.5),
|
|
|
|
|
// inactiveColor: AppColor.neutral10,
|
|
|
|
|
// thumb: CircleAvatar(backgroundColor: _settingProvider.theme == "light" ? AppColor.green50 : AppColor.neutral20),
|
|
|
|
|
// borderRadius: const BorderRadius.all(Radius.circular(30)),
|
|
|
|
|
// width: 42.toScreenWidth,
|
|
|
|
|
// height: 24.toScreenHeight,
|
|
|
|
|
// disabledOpacity: 1,
|
|
|
|
|
// ),
|
|
|
|
|
// ],
|
|
|
|
|
// );
|
|
|
|
|
// }),
|
|
|
|
|
16.height,
|
|
|
|
|
const Divider().defaultStyle(context),
|
|
|
|
|
16.height,
|
|
|
|
|
FutureBuilder(
|
|
|
|
|
future: _settingProvider.auth.isDeviceSupported(),
|
|
|
|
|
builder: (cxt, snapshot) {
|
|
|
|
|
bool isDeviceSupported = false;
|
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
|
isDeviceSupported = snapshot.data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isDeviceSupported) {
|
|
|
|
|
return Text("Your device did not support Fingerprint/Face ID.", style: AppTextStyles.tinyFont.copyWith(fontSize: 11, color: Colors.red));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
"Fingerprint/Face ID".heading5(context),
|
|
|
|
|
customSwitch(localAuth).onPress(() {
|
|
|
|
|
checkForLocalAuth(localAuth);
|
|
|
|
|
}),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
],
|
|
|
|
|
).toShadowContainer(context).paddingAll(16),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget customSwitch(bool enable) {
|
|
|
|
|
return Container(
|
|
|
|
|
width: 42.toScreenWidth,
|
|
|
|
|
height: 24.toScreenHeight,
|
|
|
|
|
alignment: enable ? Alignment.centerRight : Alignment.centerLeft,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: enable ? AppColor.green50.withOpacity(0.5) : AppColor.neutral10,
|
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(30)),
|
|
|
|
|
),
|
|
|
|
|
padding: const EdgeInsets.all(2),
|
|
|
|
|
child: Container(
|
|
|
|
|
height: 20.toScreenHeight,
|
|
|
|
|
width: 20.toScreenWidth,
|
|
|
|
|
decoration: BoxDecoration(shape: BoxShape.circle, color: enable ? AppColor.green50 : AppColor.neutral20),
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|