-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* create ZetaDateInput * create different ZetaDateInput variants * fix show error style * date validation and input mask; documentation for ZetaDateInput properties * create widgetbook * changes according to comments
- Loading branch information
1 parent
554fe7f
commit 96e5d42
Showing
7 changed files
with
497 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:zeta_example/widgets.dart'; | ||
import 'package:zeta_flutter/zeta_flutter.dart'; | ||
|
||
class DateInputExample extends StatefulWidget { | ||
static const String name = 'DateInput'; | ||
|
||
const DateInputExample({Key? key}) : super(key: key); | ||
|
||
@override | ||
State<DateInputExample> createState() => _DateInputExampleState(); | ||
} | ||
|
||
class _DateInputExampleState extends State<DateInputExample> { | ||
String? _errorText; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ExampleScaffold( | ||
name: 'Date Input', | ||
child: SingleChildScrollView( | ||
child: Column( | ||
children: [ | ||
Padding( | ||
padding: const EdgeInsets.only(top: 20), | ||
child: Text('Rounded', style: ZetaTextStyles.titleSmall), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.all(20), | ||
child: ZetaDateInput( | ||
label: 'Birthdate', | ||
hint: 'Enter birthdate', | ||
hasError: _errorText != null, | ||
errorText: _errorText ?? 'Invalid date', | ||
onChanged: (value) { | ||
if (value == null) return setState(() => _errorText = null); | ||
final now = DateTime.now(); | ||
setState( | ||
() => _errorText = value.difference(DateTime(now.year, now.month, now.day)).inDays > 0 | ||
? 'Birthdate cannot be in the future' | ||
: null, | ||
); | ||
}, | ||
), | ||
), | ||
Divider(color: Colors.grey[200]), | ||
Padding( | ||
padding: const EdgeInsets.only(top: 20), | ||
child: Text('Sharp', style: ZetaTextStyles.titleSmall), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.all(20), | ||
child: ZetaDateInput( | ||
label: 'Label', | ||
hint: 'Default hint text', | ||
errorText: 'Oops! Error hint text', | ||
rounded: false, | ||
datePattern: 'yyyy-MM-dd', | ||
), | ||
), | ||
Divider(color: Colors.grey[200]), | ||
Padding( | ||
padding: const EdgeInsets.only(top: 20), | ||
child: Text('Disabled', style: ZetaTextStyles.titleSmall), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.all(20), | ||
child: ZetaDateInput( | ||
label: 'Label', | ||
hint: 'Default hint text', | ||
enabled: false, | ||
), | ||
), | ||
Divider(color: Colors.grey[200]), | ||
Padding( | ||
padding: const EdgeInsets.only(top: 20), | ||
child: Text('Medium', style: ZetaTextStyles.titleSmall), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.all(20), | ||
child: ZetaDateInput( | ||
label: 'Label', | ||
hint: 'Default hint text', | ||
errorText: 'Oops! Error hint text', | ||
size: ZetaDateInputSize.medium, | ||
), | ||
), | ||
Divider(color: Colors.grey[200]), | ||
Padding( | ||
padding: const EdgeInsets.only(top: 20), | ||
child: Text('Small', style: ZetaTextStyles.titleSmall), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.all(20), | ||
child: ZetaDateInput( | ||
label: 'Label', | ||
hint: 'Default hint text', | ||
errorText: 'Oops! Error hint text', | ||
size: ZetaDateInputSize.small, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
example/widgetbook/pages/components/date_input_widgetbook.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:widgetbook/widgetbook.dart'; | ||
import 'package:zeta_flutter/zeta_flutter.dart'; | ||
|
||
import '../../test/test_components.dart'; | ||
|
||
Widget dateInputUseCase(BuildContext context) { | ||
String? _errorText; | ||
|
||
return WidgetbookTestWidget( | ||
widget: StatefulBuilder( | ||
builder: (context, setState) { | ||
final errorText = context.knobs.string( | ||
label: 'Error message for invalid date', | ||
initialValue: 'Invalid date', | ||
); | ||
final rounded = context.knobs.boolean(label: 'Rounded', initialValue: true); | ||
final enabled = context.knobs.boolean(label: 'Enabled', initialValue: true); | ||
final size = context.knobs.list<ZetaDateInputSize>( | ||
label: 'Size', | ||
options: ZetaDateInputSize.values, | ||
labelBuilder: (size) => size.name, | ||
); | ||
final datePattern = context.knobs.list<String>( | ||
label: 'Date pattern', | ||
options: ['MM/dd/yyyy', 'dd/MM/yyyy', 'dd.MM.yyyy', 'yyyy-MM-dd'], | ||
labelBuilder: (pattern) => pattern, | ||
); | ||
|
||
return Padding( | ||
padding: const EdgeInsets.all(ZetaSpacing.x5), | ||
child: ZetaDateInput( | ||
size: size, | ||
rounded: rounded, | ||
enabled: enabled, | ||
label: 'Birthdate', | ||
hint: 'Enter birthdate', | ||
datePattern: datePattern, | ||
hasError: _errorText != null, | ||
errorText: _errorText ?? errorText, | ||
onChanged: (value) { | ||
if (value == null) return setState(() => _errorText = null); | ||
final now = DateTime.now(); | ||
setState( | ||
() => _errorText = value.difference(DateTime(now.year, now.month, now.day)).inDays > 0 | ||
? 'Birthdate cannot be in the future' | ||
: null, | ||
); | ||
}, | ||
), | ||
); | ||
}, | ||
), | ||
); | ||
} |
Oops, something went wrong.