more refactors and logs page handling

This commit is contained in:
shenlong-tanwen
2024-10-23 02:30:46 +05:30
parent 8f47645cdb
commit a0afea04d8
90 changed files with 2386 additions and 584 deletions
@@ -40,33 +40,33 @@ class ImPasswordFormField extends StatefulWidget {
}
class _ImPasswordFormFieldState extends State<ImPasswordFormField> {
final showPassword = ValueNotifier(false);
final _showPassword = ValueNotifier(false);
@override
void dispose() {
showPassword.dispose();
_showPassword.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return ValueListenableBuilder(
valueListenable: showPassword,
valueListenable: _showPassword,
builder: (_, showPass, child) => ImTextFormField(
controller: widget.controller,
focusNode: widget.focusNode,
onChanged: widget.onChanged,
shouldObscure: !showPass,
hint: widget.hint,
label: widget.label,
focusNode: widget.focusNode,
suffixIcon: IconButton(
onPressed: () => showPassword.value = !showPassword.value,
onPressed: () => _showPassword.value = !_showPassword.value,
icon: Icon(
showPassword.value
_showPassword.value
? Symbols.visibility_off_rounded
: Symbols.visibility_rounded,
),
),
label: widget.label,
hint: widget.hint,
autoFillHints: const [AutofillHints.password],
keyboardType: TextInputType.visiblePassword,
textInputAction: widget.textInputAction,
@@ -29,18 +29,27 @@ class ImSwitchListTile<T> extends StatefulWidget {
class _ImSwitchListTileState<T> extends State<ImSwitchListTile<T>> {
// Actual switch list state
late bool isEnabled;
late bool _isEnabled;
final AppSettingService _appSettingService = di();
Future<void> set(bool enabled) async {
if (isEnabled == enabled) return;
Future<void> _set(bool enabled) async {
if (_isEnabled == enabled) return;
final value = T != bool ? widget.toAppSetting!(enabled) : enabled as T;
final value = T == bool ? enabled as T : widget.toAppSetting!(enabled);
if (value != null &&
await _appSettingService.upsert(widget.setting, value) &&
context.mounted) {
setState(() {
isEnabled = enabled;
_isEnabled = enabled;
});
}
}
Future<void> _initSetting() async {
final value = await _appSettingService.get(widget.setting);
if (context.mounted) {
setState(() {
_isEnabled = T == bool ? value as bool : widget.fromAppSetting!(value);
});
}
}
@@ -48,20 +57,14 @@ class _ImSwitchListTileState<T> extends State<ImSwitchListTile<T>> {
@override
void initState() {
super.initState();
_appSettingService.get(widget.setting).then((value) {
if (context.mounted) {
setState(() {
isEnabled = T != bool ? widget.fromAppSetting!(value) : value as bool;
});
}
});
_initSetting().ignore();
}
@override
Widget build(BuildContext context) {
return SwitchListTile(
value: isEnabled,
onChanged: (value) => set(value),
value: _isEnabled,
onChanged: (value) => unawaited(_set(value)),
);
}
}
@@ -66,21 +66,21 @@ class ImTextFormField extends StatelessWidget {
Widget build(BuildContext context) {
return TextFormField(
controller: controller,
onChanged: onChanged,
focusNode: focusNode,
obscureText: shouldObscure,
validator: validator,
decoration: InputDecoration(
labelText: label,
hintText: hint,
suffixIcon: suffixIcon,
),
autofillHints: autoFillHints,
keyboardType: keyboardType,
textInputAction: textInputAction,
readOnly: isDisabled,
obscureText: shouldObscure,
onChanged: onChanged,
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
onFieldSubmitted: onSubmitted,
validator: validator,
autofillHints: autoFillHints,
);
}
}