component updates

This commit is contained in:
MohammadTaha Basiri 2022-01-11 18:51:39 +03:30
parent 543970e708
commit 6db9921dfe
3 changed files with 25 additions and 16 deletions

View File

@ -8,11 +8,13 @@ class DidvanButton extends StatelessWidget {
final VoidCallback? onPressed; final VoidCallback? onPressed;
final String? title; final String? title;
final ButtonStyleMode style; final ButtonStyleMode style;
final bool enabled;
const DidvanButton({ const DidvanButton({
Key? key, Key? key,
this.onPressed, this.onPressed,
this.title, this.title,
this.style = ButtonStyleMode.primary, this.style = ButtonStyleMode.primary,
this.enabled = true,
}) : super(key: key); }) : super(key: key);
@override @override
@ -34,7 +36,6 @@ class DidvanButton extends StatelessWidget {
break; break;
default: default:
} }
return SizedBox( return SizedBox(
height: 48, height: 48,
width: double.infinity, width: double.infinity,
@ -46,20 +47,23 @@ class DidvanButton extends StatelessWidget {
: BorderSide.none, : BorderSide.none,
), ),
color: backgroundColor, color: backgroundColor,
onPressed: () { disabledColor: Theme.of(context).colorScheme.disabledBackground,
onPressed: !enabled
? null
: () {
FocusScope.of(context).unfocus(); FocusScope.of(context).unfocus();
onPressed?.call(); onPressed?.call();
}, },
child: _childBuilder(foregroundColor), child: _childBuilder(foregroundColor, context),
), ),
); );
} }
Widget? _childBuilder(Color color) { Widget? _childBuilder(Color color, context) {
if (title != null) { if (title != null) {
return DidvanText( return DidvanText(
title!, title!,
color: color, color: enabled ? color : Theme.of(context).colorScheme.disabledText,
); );
} }
} }

View File

@ -6,13 +6,13 @@ class DidvanScaffold extends StatelessWidget {
final List<Widget>? slivers; final List<Widget>? slivers;
final List<Widget>? children; final List<Widget>? children;
final AppBarData appBarData; final AppBarData appBarData;
final bool hasPadding; final EdgeInsets padding;
const DidvanScaffold({ const DidvanScaffold({
Key? key, Key? key,
this.slivers, this.slivers,
required this.appBarData, required this.appBarData,
this.hasPadding = true,
this.children, this.children,
this.padding = const EdgeInsets.symmetric(horizontal: 16),
}) : super(key: key); }) : super(key: key);
@override @override
@ -35,7 +35,7 @@ class DidvanScaffold extends StatelessWidget {
), ),
if (children != null) if (children != null)
SliverPadding( SliverPadding(
padding: const EdgeInsets.symmetric(horizontal: 16), padding: padding,
sliver: SliverList( sliver: SliverList(
delegate: SliverChildBuilderDelegate( delegate: SliverChildBuilderDelegate(
(context, index) => children![index], (context, index) => children![index],

View File

@ -15,7 +15,7 @@ class DidvanTextField extends StatefulWidget {
final String? hintText; final String? hintText;
final dynamic initialValue; final dynamic initialValue;
final bool obsecureText; final bool obsecureText;
final String? Function(String? value)? validator; final Function(String value)? validator;
final TextInputType? textInputType; final TextInputType? textInputType;
const DidvanTextField({ const DidvanTextField({
Key? key, Key? key,
@ -84,7 +84,9 @@ class _DidvanTextFieldState extends State<DidvanTextField> {
focusNode: _focusNode, focusNode: _focusNode,
controller: _controller, controller: _controller,
onChanged: _onChanged, onChanged: _onChanged,
validator: _validator, validator: (value) {
_validator(value);
},
obscuringCharacter: '*', obscuringCharacter: '*',
style: Theme.of(context).textTheme.bodyText1, style: Theme.of(context).textTheme.bodyText1,
decoration: InputDecoration( decoration: InputDecoration(
@ -142,7 +144,7 @@ class _DidvanTextFieldState extends State<DidvanTextField> {
Color _fillColor() { Color _fillColor() {
if (!widget.enabled) { if (!widget.enabled) {
return Theme.of(context).colorScheme.secondCTA; return Theme.of(context).colorScheme.disabledBackground;
} }
if (_focusNode.hasFocus) { if (_focusNode.hasFocus) {
return Theme.of(context).colorScheme.focused; return Theme.of(context).colorScheme.focused;
@ -172,15 +174,18 @@ class _DidvanTextFieldState extends State<DidvanTextField> {
} }
void _onChanged(String value) { void _onChanged(String value) {
setState(() {
_error = null;
});
value = value.toEnglishDigit(); value = value.toEnglishDigit();
if (widget.onChanged != null) { if (widget.onChanged != null) {
widget.onChanged!(value); widget.onChanged!(value);
} }
} }
String? _validator(String? value) { Future<String?> _validator(String? value) async {
if (widget.validator != null) { if (widget.validator != null) {
final String? error = widget.validator!(value); final String? error = await widget.validator!(value!);
if (error != null) { if (error != null) {
setState(() { setState(() {
_error = error; _error = error;