استخراج الألوان عبارة عن حزمة رفرفة تتيح لك استخراج الألوان وحسابها من واجهة المستخدم الخاصة بالتطبيق. يمكنك استخدامه لتغيير لون القطعة اعتمادًا/بناءً على لون الخلفية (عنصر واجهة مستخدم أخرى خلفها).
(قد لا يظهر مشغل الفيديو على 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 متاح تحت رخصة معهد ماساتشوستس للتكنولوجيا. انظر ملف الترخيص لمزيد من المعلومات.