-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
components/input/tonal_switch: implement TonalSwitch
- Loading branch information
1 parent
de7ef4d
commit bc23099
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flume/flume.dart'; | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class TonalSwitch extends StatelessWidget { | ||
const TonalSwitch({super.key, required this.value, required this.onChanged}); | ||
|
||
final bool value; | ||
final ValueChanged<bool> onChanged; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
if (Platform.isMacOS || Platform.isIOS) { | ||
return _CupertinoSwitch(key: key, value: value, onChanged: onChanged); | ||
} else { | ||
return _MaterialSwitch(key: key, value: value, onChanged: onChanged); | ||
} | ||
} | ||
} | ||
|
||
class _CupertinoSwitch extends StatelessWidget { | ||
const _CupertinoSwitch({ | ||
super.key, | ||
required this.value, | ||
required this.onChanged, | ||
}); | ||
|
||
final bool value; | ||
final ValueChanged<bool> onChanged; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return CupertinoSwitch( | ||
value: value, | ||
onChanged: onChanged, | ||
activeColor: context.ambiance.palette.light, | ||
trackColor: context.ambiance.palette.mediumDark, | ||
thumbColor: value | ||
? context.ambiance.palette.dark | ||
: context.ambiance.palette.light, | ||
); | ||
} | ||
} | ||
|
||
class _MaterialSwitch extends StatelessWidget { | ||
const _MaterialSwitch({ | ||
super.key, | ||
required this.value, | ||
required this.onChanged, | ||
}); | ||
|
||
final bool value; | ||
final ValueChanged<bool> onChanged; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Switch( | ||
value: value, | ||
onChanged: onChanged, | ||
activeColor: context.ambiance.palette.dark, | ||
activeTrackColor: context.ambiance.palette.light, | ||
inactiveThumbColor: context.ambiance.palette.light, | ||
inactiveTrackColor: context.ambiance.palette.mediumDark, | ||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, | ||
); | ||
} | ||
} |