-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* checkbox * remove comment * widgetbook * widgetbook
- Loading branch information
1 parent
c7cffcf
commit 86eba6f
Showing
7 changed files
with
397 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,79 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:zeta_flutter/zeta_flutter.dart'; | ||
|
||
import '../widgets.dart'; | ||
|
||
class CheckBoxExample extends StatefulWidget { | ||
static const String name = 'Checkbox'; | ||
|
||
const CheckBoxExample({Key? key}) : super(key: key); | ||
|
||
@override | ||
State<CheckBoxExample> createState() => _CheckBoxExampleState(); | ||
} | ||
|
||
class _CheckBoxExampleState extends State<CheckBoxExample> { | ||
bool? isChecked = true; | ||
bool isEnabled = true; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ExampleScaffold( | ||
name: 'Checkbox', | ||
child: Center( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | ||
children: [ | ||
Row( | ||
crossAxisAlignment: CrossAxisAlignment.center, | ||
mainAxisAlignment: MainAxisAlignment.spaceAround, | ||
children: [ | ||
ZetaCheckbox( | ||
value: isChecked, | ||
isEnabled: isEnabled, | ||
onChanged: (value) => setState(() => isChecked = value)), | ||
ElevatedButton( | ||
child: const Text('Disable'), | ||
onPressed: () => setState(() => isEnabled = !isEnabled), | ||
) | ||
], | ||
), | ||
Row(children: [const Text('Sharp Checkbox Enabled')]), | ||
getCheckBoxRow(isEnabled: true), | ||
Row(children: [const Text('Sharp Checkbox Disabled')]), | ||
getCheckBoxRow(isEnabled: false), | ||
Row(children: [const Text('Rounded Checkbox Enabled')]), | ||
getCheckBoxRow(isEnabled: true, isSharp: false), | ||
Row(children: [const Text('Rounded Checkbox Disabled')]), | ||
getCheckBoxRow(isEnabled: false, isSharp: false), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
Row getCheckBoxRow({required bool isEnabled, bool isSharp = true}) { | ||
return Row( | ||
crossAxisAlignment: CrossAxisAlignment.center, | ||
mainAxisAlignment: MainAxisAlignment.spaceAround, | ||
children: [ | ||
ZetaCheckbox( | ||
value: true, | ||
isEnabled: isEnabled, | ||
label: 'Selected', | ||
borderType: isSharp ? BorderType.sharp : BorderType.rounded, | ||
onChanged: (value) => {}), | ||
ZetaCheckbox( | ||
value: false, | ||
isEnabled: isEnabled, | ||
label: 'Indeterminate', | ||
borderType: isSharp ? BorderType.sharp : BorderType.rounded, | ||
onChanged: (value) => {}), | ||
ZetaCheckbox( | ||
value: null, | ||
borderType: isSharp ? BorderType.sharp : BorderType.rounded, | ||
isEnabled: isEnabled, | ||
onChanged: (value) => {}), | ||
]); | ||
} |
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,73 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:zeta_flutter/zeta_flutter.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
void main() { | ||
group('ZetaCheckbox Tests', () { | ||
testWidgets('Initializes with correct parameters', | ||
(WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
TestWidgetCB( | ||
widget: ZetaCheckbox( | ||
value: true, | ||
onChanged: (value) {}, | ||
borderType: BorderType.rounded, | ||
label: 'Test Checkbox', | ||
checkboxSize: Size(30, 30), | ||
)), | ||
); | ||
|
||
final checkboxFinder = find.byType(ZetaCheckbox); | ||
final ZetaCheckbox checkbox = tester.firstWidget(checkboxFinder); | ||
|
||
expect(checkbox.value, true); | ||
expect(checkbox.borderType, BorderType.rounded); | ||
expect(checkbox.label, 'Test Checkbox'); | ||
expect(checkbox.checkboxSize, Size(30, 30)); | ||
}); | ||
|
||
testWidgets('ZetaCheckbox changes state on tap', (WidgetTester tester) async { | ||
bool? checkboxValue = true; | ||
|
||
await tester.pumpWidget( | ||
TestWidgetCB( | ||
widget: ZetaCheckbox( | ||
value: checkboxValue, | ||
onChanged: (value) { | ||
checkboxValue = value; | ||
}, | ||
)), | ||
); | ||
|
||
await tester.tap(find.byType(ZetaCheckbox)); | ||
await tester.pump(); | ||
|
||
expect(checkboxValue, false); | ||
}); | ||
}); | ||
} | ||
|
||
class TestWidgetCB extends StatelessWidget { | ||
final Widget widget; | ||
|
||
const TestWidgetCB({Key? key, required this.widget}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ZetaProvider( | ||
builder: (context, theme, __) { | ||
return Builder(builder: (context) { | ||
return MaterialApp( | ||
theme: ThemeData( | ||
fontFamily: theme.fontFamily, | ||
textTheme: ZetaText.textTheme, | ||
), | ||
home: Scaffold( | ||
body: widget, | ||
), | ||
); | ||
}); | ||
}, | ||
); | ||
} | ||
} |
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,38 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:widgetbook/widgetbook.dart'; | ||
import 'package:zeta_example/pages/checkbox_example.dart'; | ||
|
||
WidgetbookComponent checkboxWidgetBook() { | ||
return WidgetbookComponent( | ||
name: 'Checkbox', | ||
useCases: [ | ||
WidgetbookUseCase( | ||
name: 'Checkbox (sharp)', | ||
builder: (context) => SingleChildScrollView( | ||
child: Padding( | ||
padding: EdgeInsets.only(top: 10), | ||
child: getCheckBoxRow(isEnabled: true), | ||
), | ||
), | ||
), | ||
WidgetbookUseCase( | ||
name: 'Checkbox (rounded)', | ||
builder: (context) => SingleChildScrollView( | ||
child: Padding( | ||
padding: EdgeInsets.only(top: 10), | ||
child: getCheckBoxRow(isEnabled: true, isSharp: false), | ||
), | ||
), | ||
), | ||
WidgetbookUseCase( | ||
name: 'Checkbox disabled (rounded)', | ||
builder: (context) => SingleChildScrollView( | ||
child: Padding( | ||
padding: EdgeInsets.only(top: 10), | ||
child: getCheckBoxRow(isEnabled: false, isSharp: false), | ||
), | ||
), | ||
), | ||
], | ||
); | ||
} |
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
Oops, something went wrong.