Created
April 8, 2023 13:40
-
-
Save kekland/d999f844e4d335ddf3057368b9b03f94 to your computer and use it in GitHub Desktop.
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
import 'package:flutter/material.dart'; | |
import 'package:widgetbook/widgetbook.dart'; | |
class ColorValue { | |
ColorValue(this.name, this.selectorFn); | |
final String name; | |
final Color Function(BuildContext) selectorFn; | |
} | |
Widget build(BuildContext context) { | |
final colorFn = context.knobs.options( | |
label: 'color', | |
options: [ | |
ColorValue( | |
'primary', | |
(context) => Theme.of(context).colorScheme.primary, | |
), | |
ColorValue( | |
'secondary', | |
(context) => Theme.of(context).colorScheme.secondary, | |
), | |
], | |
labelBuilder: (v) => v.name, | |
); | |
final color = colorFn.selectorFn(context); | |
return Container(color: color); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment