mirror of
https://github.com/foss42/apidash.git
synced 2025-05-21 08:16:29 +08:00
CheckBox -> ADCheckBox
This commit is contained in:
41
packages/apidash_design_system/lib/widgets/checkbox.dart
Normal file
41
packages/apidash_design_system/lib/widgets/checkbox.dart
Normal file
@ -0,0 +1,41 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ADCheckBox extends StatelessWidget {
|
||||
final String keyId;
|
||||
final bool value;
|
||||
final ValueChanged<bool?>? onChanged;
|
||||
final ColorScheme? colorScheme;
|
||||
const ADCheckBox({
|
||||
super.key,
|
||||
required this.keyId,
|
||||
required this.value,
|
||||
required this.onChanged,
|
||||
this.colorScheme,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var colorScheme = this.colorScheme ?? Theme.of(context).colorScheme;
|
||||
return Checkbox(
|
||||
key: Key(keyId),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
),
|
||||
side: BorderSide(
|
||||
color: colorScheme.surfaceContainerHighest,
|
||||
width: 1.5,
|
||||
),
|
||||
splashRadius: 0,
|
||||
value: value,
|
||||
onChanged: onChanged,
|
||||
checkColor: colorScheme.onPrimary,
|
||||
fillColor: WidgetStateProperty.resolveWith<Color?>(
|
||||
(Set<WidgetState> states) {
|
||||
if (states.contains(WidgetState.selected)) {
|
||||
return colorScheme.primary;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
30
packages/apidash_design_system/test/checkbox_test.dart
Normal file
30
packages/apidash_design_system/test/checkbox_test.dart
Normal file
@ -0,0 +1,30 @@
|
||||
import 'package:apidash_design_system/widgets/checkbox.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Testing for Checkbox', (tester) async {
|
||||
dynamic changedValue;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
title: 'Checkbox Widget',
|
||||
home: Scaffold(
|
||||
body: ADCheckBox(
|
||||
keyId: "1",
|
||||
value: false,
|
||||
onChanged: (value) {
|
||||
changedValue = value;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byKey(const Key("1")), findsOneWidget);
|
||||
var box = find.byKey(const Key("1"));
|
||||
await tester.tap(box);
|
||||
await tester.pump();
|
||||
await tester.pumpAndSettle();
|
||||
expect(changedValue, true);
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user