color_extract
1.0.0
컬러 추출은 앱의 위젯에서 색상을 추출하고 계산할 수있는 플러터 패키지입니다. 배경의 색상 (뒤에 다른 위젯)에 따라/위젯의 색상을 변경하는 데 사용할 수 있습니다.
(비디오 플레이어는 pub.dev에 표시되지 않을 수 있습니다. github.com을 확인하십시오)
이 데모에서는 위젯을 카멜레온처럼 어떻게 변경할 수 있습니까?.
pubspec.yaml 에 다음을 추가하십시오.
dependencies :
color_extract : ^1.0.1 그런 다음 flutter pub get 실행하십시오.
ColorExtractor 평균 색상을 추출하려는 위젯입니다. RecaintBoundary의 래퍼 역할을하므로 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 라이센스에 따라 사용할 수 있습니다. 자세한 내용은 라이센스 파일을 참조하십시오.