| 1 | import 'dart:ui'; |
| 2 | import 'package:flutter/cupertino.dart'; |
| 3 | import 'package:flutter/material.dart'; |
| 4 | |
| 5 | class RoundedCheckbox extends StatelessWidget { |
| 6 | RoundedCheckbox({Key? key, required this.value}) : super(key: key); |
| 7 | |
| 8 | final bool value; |
| 9 | |
| 10 | @override |
| 11 | Widget build(BuildContext context) { |
| 12 | // Unchecked renders nothing at all, so without an explicit `checked` state |
| 13 | // the selection is invisible to screen readers. |
| 14 | final Widget indicator = value |
| 15 | ? Container( |
| 16 | height: 20.0, |
| 17 | width: 20.0, |
| 18 | decoration: BoxDecoration( |
| 19 | borderRadius: BorderRadius.all(Radius.circular(50.0)), |
| 20 | color: Theme.of(context).colorScheme.primary, |
| 21 | ), |
| 22 | child: Icon( |
| 23 | Icons.check, |
| 24 | color: Theme.of(context).colorScheme.surface, |
| 25 | size: 14.0, |
| 26 | )) |
| 27 | : Offstage(); |
| 28 | |
| 29 | // Deliberately not a semantics container: the state merges into the |
| 30 | // enclosing row/option node instead of adding a second focus stop. |
| 31 | return Semantics(checked: value, child: indicator); |
| 32 | } |
| 33 | } |