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 String? title;
final ButtonStyleMode style;
final bool enabled;
const DidvanButton({
Key? key,
this.onPressed,
this.title,
this.style = ButtonStyleMode.primary,
this.enabled = true,
}) : super(key: key);
@override
@ -34,7 +36,6 @@ class DidvanButton extends StatelessWidget {
break;
default:
}
return SizedBox(
height: 48,
width: double.infinity,
@ -46,20 +47,23 @@ class DidvanButton extends StatelessWidget {
: BorderSide.none,
),
color: backgroundColor,
onPressed: () {
disabledColor: Theme.of(context).colorScheme.disabledBackground,
onPressed: !enabled
? null
: () {
FocusScope.of(context).unfocus();
onPressed?.call();
},
child: _childBuilder(foregroundColor),
child: _childBuilder(foregroundColor, context),
),
);
}
Widget? _childBuilder(Color color) {
Widget? _childBuilder(Color color, context) {
if (title != null) {
return DidvanText(
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>? children;
final AppBarData appBarData;
final bool hasPadding;
final EdgeInsets padding;
const DidvanScaffold({
Key? key,
this.slivers,
required this.appBarData,
this.hasPadding = true,
this.children,
this.padding = const EdgeInsets.symmetric(horizontal: 16),
}) : super(key: key);
@override
@ -35,7 +35,7 @@ class DidvanScaffold extends StatelessWidget {
),
if (children != null)
SliverPadding(
padding: const EdgeInsets.symmetric(horizontal: 16),
padding: padding,
sliver: SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) => children![index],

View File

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