color_extract
1.0.0
Color Extractは、アプリのウィジェットから色を抽出および計算できるフラッターパッケージです。それを使用して、背景の色に応じて/に基づいてウィジェットの色を変更できます(背後の他のウィジェット)。
(ビデオプレーヤーはpub.devに表示されない場合があります、github.comを確認してください)
このデモでは、カメレオンのようにウィジェットを変える方法をご覧ください。
pubspec.yamlに次のものを追加します。
dependencies :
color_extract : ^1.0.1その後、 flutter pub getを実行します。
ColorExtractor 、平均色を抽出したいウィジェットです。繰り返しのラッパーとして機能しているため、代替として再boundaryを利用できます。
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ライセンスの下で利用できます。詳細については、ライセンスファイルを参照してください。