Skip to content

Instantly share code, notes, and snippets.

@kekland
Created April 8, 2023 13:40
Show Gist options
  • Save kekland/d999f844e4d335ddf3057368b9b03f94 to your computer and use it in GitHub Desktop.
Save kekland/d999f844e4d335ddf3057368b9b03f94 to your computer and use it in GitHub Desktop.
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