color_extract
1.0.0
颜色提取物是一个扑朔迷离的软件包,可让您从应用程序的小部件中提取和计算颜色。您可以根据背景的颜色(背后的另一个小部件)来使用它来更改小部件的颜色。
(视频播放器可能不会在pub.dev上显示,请检查github.com)
在此演示中,看看如何使小部件更改颜色,例如变色龙?
将以下内容添加到您的pubspec.yaml :
dependencies :
color_extract : ^1.0.1然后运行flutter pub get 。
ColorExtractor是我们要从中提取平均颜色的小部件。它是RepaintBoundary的包装纸,因此您可以利用RepaintBoundary作为替代方案。
ColorExtractor (
boundaryKey : GlobalKey (),
child : Container (
width : 200 ,
height : 200 ,
color : Colors .red,
),
); ColorAverager小部件计算ColorExtractor或RepaintBoundary的特定部分的平均颜色。它的应用可用于确定特定区域的主要颜色,例如徽标,图像背后的背景。
ColorAverager (
boundaryKey : GlobalKey (),
child : SizedBox (
width : 50 ,
height : 50 ,
),
onChanged : (color) {
// Handle the new average color.
},
);您也可以使用ColorAveragerController来编程计算平均颜色。
final controller = ColorAveragerController ();
// ... render the widget ...
final avgColor = await controller. calculateAvgColor (); import 'package:flutter/material.dart' ;
import 'package:color_extract/color_extract.dart' ;
class MyHomePage extends StatelessWidget {
@override
Widget build ( BuildContext context) {
return Scaffold (
body : Stack (
children : [
ColorExtractor (
boundaryKey : boundaryKey,
child : Container (
width : 200 ,
height : 200 ,
color : Colors .blue,
),
),
ColorAverager (
// boundaryKey should be the same one in the above ColorExtractor boundaryKey
boundaryKey : boundaryKey,
// You can use the controller (ColorAveragerController) too.
// controller: controller,
child : const SizedBox (width : 50 , height : 50 ),
onChanged : (color) {
// Do something with the average color.
// color should be = Colors.blue
},
)
],
)
);
}
}itisnajim,[email protected]
Color_Extract可在MIT许可下获得。有关更多信息,请参见许可证文件。