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許可下獲得。有關更多信息,請參見許可證文件。