gpt4 book ai didi

android - Flutter:圆形颜色选择器(包:flutter_colorpicker)

转载 作者:行者123 更新时间:2023-12-04 23:57:20 24 4
gpt4 key购买 nike

我用了this flutter 包在我的应用程序中实现颜色选择器。我的 Widget 看起来像这样:

     ColorPicker(
pickerColor: model.color,
onColorChanged: (color) {
...
},
showLabel: false,
pickerAreaHeightPercent: 0.4,
)

这工作正常,在 UI 中看起来像这样:

color picker

现在我想知道如何实现经典的圆形颜色选择器。我没有在官方文档中找到示例,但包描述中有一个屏幕截图显示了这一点:

circular color picker

有谁知道如何使用相同的包来实现这个,或者可以提示我举个例子。

最佳答案

请查看此内容,您需要将调色板类型设为 paletteType: PaletteType.hueWheel,。使用与使用相同的包。

import 'package:flutter/material.dart';
import 'package:flutter_colorpicker/flutter_colorpicker.dart';


void main() => runApp(const MaterialApp(home: MyApp()));

class MyApp extends StatefulWidget {
const MyApp({Key key}) : super(key: key);

@override
State<StatefulWidget> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
bool lightTheme = true;
Color currentColor = Colors.amber;
List<Color> currentColors = [Colors.yellow, Colors.green];
List<Color> colorHistory = [];

void changeColor(Color color) => setState(() => currentColor = color);
void changeColors(List<Color> colors) => setState(() => currentColors = colors);

@override
Widget build(BuildContext context) {
final foregroundColor = useWhiteForeground(currentColor) ? Colors.white : Colors.black;
return AnimatedTheme(
data: lightTheme ? ThemeData.light() : ThemeData.dark(),
child: Builder(builder: (context) {
return Scaffold(
appBar: AppBar(
title: const Text('Flutter Color Picker Example'),
backgroundColor: currentColor,
foregroundColor: foregroundColor,

),
body: Container(
child: InkWell(
onTap: (){
showColorPicker();
},
child: Center(child: Text("Color Picker")),
),
),
);
}),
);
}

void showColorPicker() {
showDialog(context: context, builder: (BuildContext context){
return AlertDialog(
title: Text("Pick a color"),
content: SingleChildScrollView(
child: ColorPicker(
pickerColor: Color(0xff443a49),
paletteType: PaletteType.hueWheel,
),
),
);
});
}
}

输出

enter image description here

关于android - Flutter:圆形颜色选择器(包:flutter_colorpicker),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70408001/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com