|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | + |
| 3 | +class ColorFiltersDemo extends StatefulWidget { |
| 4 | + @override |
| 5 | + State<StatefulWidget> createState() => ColorFilterDemoState(); |
| 6 | +} |
| 7 | + |
| 8 | +class ColorFilterDemoState extends State<ColorFiltersDemo> { |
| 9 | + int selectedBlendModeIndex = 0; |
| 10 | + |
| 11 | + Map<String, BlendMode> blendModeMap = Map(); |
| 12 | + |
| 13 | + @override |
| 14 | + void initState() { |
| 15 | + super.initState(); |
| 16 | + blendModeMap.putIfAbsent("Normal", () => BlendMode.clear); |
| 17 | + blendModeMap.putIfAbsent("Color Burn", () => BlendMode.colorBurn); |
| 18 | + blendModeMap.putIfAbsent("Color Dodge", () => BlendMode.colorDodge); |
| 19 | + blendModeMap.putIfAbsent("Saturation", () => BlendMode.saturation); |
| 20 | + blendModeMap.putIfAbsent("Hue", () => BlendMode.hue); |
| 21 | + blendModeMap.putIfAbsent("Soft light", () => BlendMode.softLight); |
| 22 | + blendModeMap.putIfAbsent("Overlay", () => BlendMode.overlay); |
| 23 | + blendModeMap.putIfAbsent("Multiply", () => BlendMode.multiply); |
| 24 | + blendModeMap.putIfAbsent("Luminosity", () => BlendMode.luminosity); |
| 25 | + blendModeMap.putIfAbsent("Plus", () => BlendMode.plus); |
| 26 | + blendModeMap.putIfAbsent("Exclusion", () => BlendMode.exclusion); |
| 27 | + blendModeMap.putIfAbsent("Hard Light", () => BlendMode.hardLight); |
| 28 | + blendModeMap.putIfAbsent("Lighten", () => BlendMode.lighten); |
| 29 | + blendModeMap.putIfAbsent("Screen", () => BlendMode.screen); |
| 30 | + blendModeMap.putIfAbsent("Modulate", () => BlendMode.modulate); |
| 31 | + blendModeMap.putIfAbsent("Difference", () => BlendMode.difference); |
| 32 | + blendModeMap.putIfAbsent("Darken", () => BlendMode.darken); |
| 33 | + } |
| 34 | + |
| 35 | + @override |
| 36 | + Widget build(BuildContext context) { |
| 37 | + return MaterialApp( |
| 38 | + debugShowCheckedModeBanner: false, |
| 39 | + home: Scaffold( |
| 40 | + body: Stack( |
| 41 | + children: <Widget>[ |
| 42 | + Image.asset( |
| 43 | + "images/background_bg.jpg", |
| 44 | + height: double.maxFinite, |
| 45 | + width: double.maxFinite, |
| 46 | + fit: BoxFit.fitHeight, |
| 47 | + color: selectedBlendModeIndex == 0 ? null : Colors.red, |
| 48 | + colorBlendMode: selectedBlendModeIndex == 0 |
| 49 | + ? null |
| 50 | + : blendModeMap.values.elementAt(selectedBlendModeIndex), |
| 51 | + ), |
| 52 | + Positioned( |
| 53 | + left: 0.0, |
| 54 | + bottom: 0.0, |
| 55 | + height: 100.0, |
| 56 | + right: 0.0, |
| 57 | + child: Container( |
| 58 | + color: Colors.black.withOpacity(0.5), |
| 59 | + child: Center( |
| 60 | + child: Container( |
| 61 | + margin: EdgeInsets.only(bottom: 20.0), |
| 62 | + height: 40.0, |
| 63 | + child: ListView.builder( |
| 64 | + padding: EdgeInsets.symmetric(horizontal: 8.0), |
| 65 | + shrinkWrap: true, |
| 66 | + scrollDirection: Axis.horizontal, |
| 67 | + itemCount: blendModeMap.keys.length, |
| 68 | + itemBuilder: (context, index) { |
| 69 | + return Container( |
| 70 | + padding: EdgeInsets.all(4.0), |
| 71 | + child: ChoiceChip( |
| 72 | + padding: EdgeInsets.symmetric( |
| 73 | + horizontal: 8.0, vertical: 0.0), |
| 74 | + labelStyle: TextStyle( |
| 75 | + color: Colors.white, |
| 76 | + fontSize: (selectedBlendModeIndex == index) |
| 77 | + ? 15.0 |
| 78 | + : 13.0, |
| 79 | + fontWeight: (selectedBlendModeIndex == index) |
| 80 | + ? FontWeight.bold |
| 81 | + : FontWeight.normal), |
| 82 | + backgroundColor: Colors.black.withOpacity(0.8), |
| 83 | + selectedColor: Colors.blue, |
| 84 | + label: Center( |
| 85 | + child: Text(blendModeMap.keys.elementAt(index)), |
| 86 | + ), |
| 87 | + selected: selectedBlendModeIndex == index, |
| 88 | + onSelected: (bool selected) { |
| 89 | + setState(() { |
| 90 | + selectedBlendModeIndex = |
| 91 | + selected ? index : null; |
| 92 | + }); |
| 93 | + }), |
| 94 | + ); |
| 95 | + }, |
| 96 | + ), |
| 97 | + ), |
| 98 | + ), |
| 99 | + ), |
| 100 | + ), |
| 101 | + ], |
| 102 | + ), |
| 103 | + ), |
| 104 | + ); |
| 105 | + } |
| 106 | +} |
0 commit comments