Checkbox
In ProgressDark modeRTLA checkable input with checked, unchecked, and indeterminate states.
Installation
Copy the component into your project using the CLI:
$ronakcn add checkbox
Usage
Import and use the component in your Flutter widget tree:
lib/pages/example.dart
import 'package:flutter/material.dart';
import '../components/checkbox/checkbox.dart';
class ExamplePage extends StatelessWidget {
const ExamplePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('RcnCheckbox Example')),
body: Center(
child: RcnCheckbox(
// Configure props here
),
),
);
}
}Variants
Checkbox ships with the following variants:
default
A standard checkbox.
checked
Pre-checked checkbox state.
unchecked
Unchecked checkbox state.
indeterminate
Partial / indeterminate state.
disabled
Non-interactive disabled checkbox.
with-description
Checkbox with a helper description.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | bool? | false | Current checked state. |
onChanged* | ValueChanged<bool?> | — | Called when state changes. |
label | String? | null | Label displayed beside checkbox. |
description | String? | null | Helper text below the label. |
enabled | bool | true | Whether the checkbox is enabled. |
tristate | bool | false | Allows indeterminate state. |
Source files
lib/components/ui/checkbox.dart
import 'package:flutter/material.dart';
class RcnCheckbox extends StatelessWidget {
const RcnCheckbox({
super.key,
this.value = false,
required this.onChanged,
this.label,
this.description,
this.enabled = true,
this.tristate = false,
});
final bool? value;
final ValueChanged<bool?> onChanged;
final String? label;
final String? description;
final bool enabled;
final bool tristate;
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return GestureDetector(
onTap: enabled ? () => onChanged(value == true ? false : true) : null,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Checkbox(
value: value,
tristate: tristate,
onChanged: enabled ? onChanged : null,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)),
),
if (label != null)
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 2),
Text(label!, style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: colors.onSurface)),
if (description != null)
Text(description!, style: TextStyle(fontSize: 12, color: colors.onSurface.withOpacity(0.6))),
],
),
),
],
),
);
}
}Version
0.1.0 · input category