mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-05-13 11:42:17 -04:00
more refactor
This commit is contained in:
parent
b83aa3a64b
commit
c7b541c643
45 changed files with 860 additions and 336 deletions
127
lib/tools/enter_password.dart
Normal file
127
lib/tools/enter_password.dart
Normal file
|
@ -0,0 +1,127 @@
|
|||
import 'package:awesome_extensions/awesome_extensions.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_translate/flutter_translate.dart';
|
||||
|
||||
import '../theme/theme.dart';
|
||||
|
||||
class EnterPasswordDialog extends StatefulWidget {
|
||||
const EnterPasswordDialog({
|
||||
this.matchPass,
|
||||
this.description,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final String? matchPass;
|
||||
final String? description;
|
||||
|
||||
@override
|
||||
EnterPasswordDialogState createState() => EnterPasswordDialogState();
|
||||
|
||||
@override
|
||||
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
||||
super.debugFillProperties(properties);
|
||||
properties
|
||||
..add(StringProperty('reenter', matchPass))
|
||||
..add(StringProperty('description', description));
|
||||
}
|
||||
}
|
||||
|
||||
class EnterPasswordDialogState extends State<EnterPasswordDialog> {
|
||||
final passwordController = TextEditingController();
|
||||
final focusNode = FocusNode();
|
||||
final formKey = GlobalKey<FormState>();
|
||||
bool _passwordVisible = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
passwordController.dispose();
|
||||
focusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
// ignore: prefer_expression_function_bodies
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scale = theme.extension<ScaleScheme>()!;
|
||||
|
||||
return Dialog(
|
||||
backgroundColor: scale.grayScale.subtleBackground,
|
||||
child: Form(
|
||||
key: formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
widget.matchPass == null
|
||||
? translate('enter_password_dialog.enter_password')
|
||||
: translate('enter_password_dialog.reenter_password'),
|
||||
style: theme.textTheme.titleLarge,
|
||||
).paddingAll(16),
|
||||
TextField(
|
||||
controller: passwordController,
|
||||
focusNode: focusNode,
|
||||
autofocus: true,
|
||||
enableSuggestions: false,
|
||||
obscureText:
|
||||
!_passwordVisible, //This will obscure text dynamically
|
||||
inputFormatters: <TextInputFormatter>[
|
||||
FilteringTextInputFormatter.singleLineFormatter
|
||||
],
|
||||
onSubmitted: (password) {
|
||||
Navigator.pop(context, password);
|
||||
},
|
||||
onChanged: (_) {
|
||||
setState(() {});
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: widget.matchPass == null
|
||||
? null
|
||||
: Icon(Icons.check_circle,
|
||||
color: passwordController.text == widget.matchPass
|
||||
? scale.primaryScale.background
|
||||
: scale.grayScale.subtleBackground),
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
_passwordVisible
|
||||
? Icons.visibility
|
||||
: Icons.visibility_off,
|
||||
color: scale.primaryScale.text,
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_passwordVisible = !_passwordVisible;
|
||||
});
|
||||
},
|
||||
),
|
||||
)).paddingAll(16),
|
||||
if (widget.description != null)
|
||||
SizedBox(
|
||||
width: 400,
|
||||
child: Text(
|
||||
widget.description!,
|
||||
textAlign: TextAlign.center,
|
||||
).paddingAll(16))
|
||||
],
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
@override
|
||||
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
||||
super.debugFillProperties(properties);
|
||||
properties
|
||||
..add(DiagnosticsProperty<TextEditingController>(
|
||||
'passwordController', passwordController))
|
||||
..add(DiagnosticsProperty<FocusNode>('focusNode', focusNode))
|
||||
..add(DiagnosticsProperty<GlobalKey<FormState>>('formKey', formKey));
|
||||
}
|
||||
}
|
141
lib/tools/enter_pin.dart
Normal file
141
lib/tools/enter_pin.dart
Normal file
|
@ -0,0 +1,141 @@
|
|||
import 'package:awesome_extensions/awesome_extensions.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_translate/flutter_translate.dart';
|
||||
import 'package:pinput/pinput.dart';
|
||||
|
||||
import '../theme/theme.dart';
|
||||
|
||||
class EnterPinDialog extends StatefulWidget {
|
||||
const EnterPinDialog({
|
||||
required this.reenter,
|
||||
required this.description,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final bool reenter;
|
||||
final String? description;
|
||||
|
||||
@override
|
||||
EnterPinDialogState createState() => EnterPinDialogState();
|
||||
|
||||
@override
|
||||
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
||||
super.debugFillProperties(properties);
|
||||
properties
|
||||
..add(StringProperty('description', description))
|
||||
..add(DiagnosticsProperty<bool>('reenter', reenter));
|
||||
}
|
||||
}
|
||||
|
||||
class EnterPinDialogState extends State<EnterPinDialog> {
|
||||
final pinController = TextEditingController();
|
||||
final focusNode = FocusNode();
|
||||
final formKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
pinController.dispose();
|
||||
focusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
// ignore: prefer_expression_function_bodies
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scale = theme.extension<ScaleScheme>()!;
|
||||
final focusedBorderColor = scale.primaryScale.hoverBorder;
|
||||
final fillColor = scale.primaryScale.elementBackground;
|
||||
final borderColor = scale.primaryScale.border;
|
||||
|
||||
final defaultPinTheme = PinTheme(
|
||||
width: 56,
|
||||
height: 60,
|
||||
textStyle: TextStyle(fontSize: 22, color: scale.primaryScale.text),
|
||||
decoration: BoxDecoration(
|
||||
color: fillColor,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: borderColor),
|
||||
),
|
||||
);
|
||||
|
||||
/// Optionally you can use form to validate the Pinput
|
||||
return Dialog(
|
||||
backgroundColor: scale.grayScale.subtleBackground,
|
||||
child: Form(
|
||||
key: formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
!widget.reenter
|
||||
? translate('enter_pin_dialog.enter_pin')
|
||||
: translate('enter_pin_dialog.reenter_pin'),
|
||||
style: theme.textTheme.titleLarge,
|
||||
).paddingAll(16),
|
||||
Directionality(
|
||||
// Specify direction if desired
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Pinput(
|
||||
controller: pinController,
|
||||
focusNode: focusNode,
|
||||
autofocus: true,
|
||||
defaultPinTheme: defaultPinTheme,
|
||||
enableSuggestions: false,
|
||||
inputFormatters: <TextInputFormatter>[
|
||||
FilteringTextInputFormatter.digitsOnly
|
||||
],
|
||||
hapticFeedbackType: HapticFeedbackType.lightImpact,
|
||||
onCompleted: (pin) {
|
||||
Navigator.pop(context, pin);
|
||||
},
|
||||
cursor: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Container(
|
||||
margin: const EdgeInsets.only(bottom: 9),
|
||||
width: 22,
|
||||
height: 1,
|
||||
color: focusedBorderColor,
|
||||
),
|
||||
],
|
||||
),
|
||||
focusedPinTheme: defaultPinTheme.copyWith(
|
||||
height: 68,
|
||||
width: 64,
|
||||
decoration: defaultPinTheme.decoration!.copyWith(
|
||||
border: Border.all(color: borderColor),
|
||||
),
|
||||
),
|
||||
).paddingAll(16),
|
||||
),
|
||||
if (widget.description != null)
|
||||
SizedBox(
|
||||
width: 400,
|
||||
child: Text(
|
||||
widget.description!,
|
||||
textAlign: TextAlign.center,
|
||||
).paddingAll(16))
|
||||
],
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
@override
|
||||
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
||||
super.debugFillProperties(properties);
|
||||
properties
|
||||
..add(DiagnosticsProperty<TextEditingController>(
|
||||
'pinController', pinController))
|
||||
..add(DiagnosticsProperty<FocusNode>('focusNode', focusNode))
|
||||
..add(DiagnosticsProperty<GlobalKey<FormState>>('formKey', formKey));
|
||||
}
|
||||
}
|
|
@ -1,10 +1,13 @@
|
|||
export 'animations.dart';
|
||||
export 'enter_password.dart';
|
||||
export 'enter_pin.dart';
|
||||
export 'loggy.dart';
|
||||
export 'phono_byte.dart';
|
||||
export 'responsive.dart';
|
||||
export 'scanner_error_widget.dart';
|
||||
export 'shared_preferences.dart';
|
||||
export 'state_logger.dart';
|
||||
export 'stream_listenable.dart';
|
||||
export 'stream_wrapper_cubit.dart';
|
||||
export 'widget_helpers.dart';
|
||||
export 'window_control.dart';
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:awesome_extensions/awesome_extensions.dart';
|
||||
import 'package:blurry_modal_progress_hud/blurry_modal_progress_hud.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
||||
import 'package:flutter_translate/flutter_translate.dart';
|
||||
import 'package:motion_toast/motion_toast.dart';
|
||||
|
@ -60,6 +61,22 @@ extension AsyncValueBuilderExt<T> on AsyncValue<T> {
|
|||
asyncValueBuilder<T>(this, builder);
|
||||
}
|
||||
|
||||
class AsyncBlocBuilder<B extends StateStreamable<AsyncValue<S>>, S>
|
||||
extends BlocBuilder<B, AsyncValue<S>> {
|
||||
AsyncBlocBuilder({
|
||||
required BlocWidgetBuilder<S> builder,
|
||||
Widget Function(BuildContext)? loading,
|
||||
Widget Function(BuildContext, Object, StackTrace?)? error,
|
||||
super.key,
|
||||
super.bloc,
|
||||
super.buildWhen,
|
||||
}) : super(
|
||||
builder: (context, state) => state.when(
|
||||
loading: () => (loading ?? waitingPage)(context),
|
||||
error: (e, st) => (error ?? errorPage)(context, e, st),
|
||||
data: (d) => builder(context, d)));
|
||||
}
|
||||
|
||||
Future<void> showErrorModal(
|
||||
BuildContext context, String title, String text) async {
|
||||
await QuickAlert.show(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue