1// Copyright 2014 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'package:flutter/cupertino.dart';
6
7/// Flutter code sample for [CupertinoCheckbox].
8
9void main() => runApp(const CupertinoCheckboxApp());
10
11class CupertinoCheckboxApp extends StatelessWidget {
12 const CupertinoCheckboxApp({super.key});
13
14 @override
15 Widget build(BuildContext context) {
16 return const CupertinoApp(
17 theme: CupertinoThemeData(brightness: Brightness.light),
18 home: CupertinoPageScaffold(
19 navigationBar: CupertinoNavigationBar(middle: Text('CupertinoCheckbox Example')),
20 child: SafeArea(child: CupertinoCheckboxExample()),
21 ),
22 );
23 }
24}
25
26class CupertinoCheckboxExample extends StatefulWidget {
27 const CupertinoCheckboxExample({super.key});
28
29 @override
30 State<CupertinoCheckboxExample> createState() => _CupertinoCheckboxExampleState();
31}
32
33class _CupertinoCheckboxExampleState extends State<CupertinoCheckboxExample> {
34 bool? isChecked = true;
35
36 @override
37 Widget build(BuildContext context) {
38 return CupertinoCheckbox(
39 checkColor: CupertinoColors.white,
40 // Set tristate to true to make the checkbox display a null value
41 // in addition to the default true and false values.
42 tristate: true,
43 value: isChecked,
44 onChanged: (bool? value) {
45 setState(() {
46 isChecked = value;
47 });
48 },
49 );
50 }
51}
52