Download flutter/examples/api/lib/cupertino/switch/cupertino_switch.0.dart from luom2645/agent-workspace: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/luom2645/agent-workspace/resolve/main/flutter/examples/api/lib/cupertino/switch/cupertino_switch.0.dart
- Command line
-
hf download hf://luom2645/agent-workspace/flutter/examples/api/lib/cupertino/switch/cupertino_switch.0.dart
-
curl -L -o cupertino_switch.0.dart https://huggingface.co/luom2645/agent-workspace/resolve/main/flutter/examples/api/lib/cupertino/switch/cupertino_switch.0.dart
1.49 kB
| // Copyright 2014 The Flutter Authors. All rights reserved. | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| import 'package:flutter/cupertino.dart'; | |
| /// Flutter code sample for [CupertinoSwitch]. | |
| void main() => runApp(const CupertinoSwitchApp()); | |
| class CupertinoSwitchApp extends StatelessWidget { | |
| const CupertinoSwitchApp({super.key}); | |
| Widget build(BuildContext context) { | |
| return const CupertinoApp( | |
| theme: CupertinoThemeData(brightness: Brightness.light), | |
| home: CupertinoSwitchExample(), | |
| ); | |
| } | |
| } | |
| class CupertinoSwitchExample extends StatefulWidget { | |
| const CupertinoSwitchExample({super.key}); | |
| State<CupertinoSwitchExample> createState() => _CupertinoSwitchExampleState(); | |
| } | |
| class _CupertinoSwitchExampleState extends State<CupertinoSwitchExample> { | |
| bool switchValue = true; | |
| Widget build(BuildContext context) { | |
| return CupertinoPageScaffold( | |
| navigationBar: const CupertinoNavigationBar(middle: Text('CupertinoSwitch Sample')), | |
| child: Center( | |
| child: CupertinoSwitch( | |
| // This bool value toggles the switch. | |
| value: switchValue, | |
| activeTrackColor: CupertinoColors.activeBlue, | |
| onChanged: (bool? value) { | |
| // This is called when the user toggles the switch. | |
| setState(() { | |
| switchValue = value ?? false; | |
| }); | |
| }, | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |