flutter_colorpicker 0.4.0-nullsafety.0
flutter_colorpicker: ^0.4.0-nullsafety.0 copied to clipboard
A HSV(HSB)/HSL color picker inspired by chrome devtools and a material color picker for your flutter app.
example/lib/main.dart
import 'package:flutter/material.dart';
// import 'package:flutter/foundation.dart'
// show debugDefaultTargetPlatformOverride;
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
void main() {
// debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
runApp(MaterialApp(home: MyApp()));
}
class MyApp extends StatefulWidget {
@override
State<StatefulWidget> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool lightTheme = true;
Color currentColor = Colors.limeAccent;
List<Color> currentColors = [Colors.limeAccent, Colors.green];
void changeColor(Color color) => setState(() => currentColor = color);
void changeColors(List<Color> colors) => setState(() => currentColors = colors);
@override
Widget build(BuildContext context) {
return Theme(
data: lightTheme ? ThemeData.light() : ThemeData.dark(),
child: DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
title: GestureDetector(
child: Text('Flutter Color Picker Example'),
onDoubleTap: () => setState(() => lightTheme = !lightTheme),
),
bottom: TabBar(
tabs: <Widget>[
const Tab(text: 'HSV'),
const Tab(text: 'Material'),
const Tab(text: 'Block'),
],
),
),
body: TabBarView(
physics: const NeverScrollableScrollPhysics(),
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
elevation: 3.0,
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
titlePadding: const EdgeInsets.all(0.0),
contentPadding: const EdgeInsets.all(0.0),
content: SingleChildScrollView(
child: ColorPicker(
pickerColor: currentColor,
onColorChanged: changeColor,
colorPickerWidth: 300.0,
pickerAreaHeightPercent: 0.7,
enableAlpha: true,
displayThumbColor: true,
showLabel: true,
paletteType: PaletteType.hsv,
pickerAreaBorderRadius: const BorderRadius.only(
topLeft: const Radius.circular(2.0),
topRight: const Radius.circular(2.0),
),
),
),
);
},
);
},
child: const Text('Change me'),
color: currentColor,
textColor: useWhiteForeground(currentColor)
? const Color(0xffffffff)
: const Color(0xff000000),
),
RaisedButton(
elevation: 3.0,
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
titlePadding: const EdgeInsets.all(0.0),
contentPadding: const EdgeInsets.all(0.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25.0),
),
content: SingleChildScrollView(
child: SlidePicker(
pickerColor: currentColor,
onColorChanged: changeColor,
paletteType: PaletteType.rgb,
enableAlpha: false,
displayThumbColor: true,
showLabel: false,
showIndicator: true,
indicatorBorderRadius:
const BorderRadius.vertical(
top: const Radius.circular(25.0),
),
),
),
);
},
);
},
child: const Text('Change me again'),
color: currentColor,
textColor: useWhiteForeground(currentColor)
? const Color(0xffffffff)
: const Color(0xff000000),
),
],
),
Center(
child: RaisedButton(
elevation: 3.0,
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
titlePadding: const EdgeInsets.all(0.0),
contentPadding: const EdgeInsets.all(0.0),
content: SingleChildScrollView(
child: MaterialPicker(
pickerColor: currentColor,
onColorChanged: changeColor,
enableLabel: true,
),
),
);
},
);
},
child: const Text('Change me'),
color: currentColor,
textColor: useWhiteForeground(currentColor)
? const Color(0xffffffff)
: const Color(0xff000000),
),
),
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
elevation: 3.0,
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Select a color'),
content: SingleChildScrollView(
child: BlockPicker(
pickerColor: currentColor,
onColorChanged: changeColor,
),
),
);
},
);
},
child: const Text('Change me'),
color: currentColor,
textColor: useWhiteForeground(currentColor)
? const Color(0xffffffff)
: const Color(0xff000000),
),
RaisedButton(
elevation: 3.0,
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Select colors'),
content: SingleChildScrollView(
child: MultipleChoiceBlockPicker(
pickerColors: currentColors,
onColorsChanged: changeColors,
),
),
);
},
);
},
child: const Text('Change me again'),
color: currentColor,
textColor: useWhiteForeground(currentColor)
? const Color(0xffffffff)
: const Color(0xff000000),
)
]
),
),
],
),
),
),
);
}
}