11import 'package:flutter/material.dart' ;
22import 'package:magic_epaper_app/constants.dart' ;
3+ import 'package:magic_epaper_app/provider/getitlocator.dart' ;
34import 'package:magic_epaper_app/util/epd/epd.dart' ;
45import 'package:magic_epaper_app/util/epd/gdey037z03.dart' ;
56import 'package:magic_epaper_app/util/epd/gdey037z03bw.dart' ;
67import 'package:magic_epaper_app/view/image_editor.dart' ;
8+ import 'package:provider/provider.dart' ;
9+ import 'package:magic_epaper_app/provider/color_palette_provider.dart' ;
710import 'package:magic_epaper_app/view/widget/display_card.dart' ;
811
912class DisplaySelectionScreen extends StatefulWidget {
@@ -19,60 +22,65 @@ class _DisplaySelectionScreenState extends State<DisplaySelectionScreen> {
1922
2023 @override
2124 Widget build (BuildContext context) {
22- return Scaffold (
23- backgroundColor: Colors .white,
24- appBar: AppBar (
25- backgroundColor: colorAccent,
26- elevation: 0 ,
27- title: const Padding (
28- padding: EdgeInsets .fromLTRB (5 , 16 , 16 , 5 ),
29- child: Column (
30- crossAxisAlignment: CrossAxisAlignment .start,
31- children: [
32- Text ('Magic ePaper' ,
33- style: TextStyle (
34- fontSize: 24 ,
35- fontWeight: FontWeight .bold,
36- color: Colors .white,
37- )),
38- SizedBox (height: 8 ),
39- Text ('Select your ePaper display type' ,
40- style: TextStyle (
41- fontSize: 16 ,
42- color: Colors .white,
43- )),
44- ],
45- ),
46- ),
47- toolbarHeight: 85 ,
48- ),
49- body: SafeArea (
50- child: Padding (
51- padding: const EdgeInsets .fromLTRB (10.0 , 14 , 16.0 , 16.0 ),
52- child: Column (
53- children: [
54- Expanded (
55- child: GridView .builder (
56- gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount (
57- crossAxisCount: 2 ,
58- childAspectRatio: 0.6 ,
59- mainAxisSpacing: 8 ,
60- crossAxisSpacing: 8 ,
61- ),
62- itemCount: displays.length,
63- itemBuilder: (context, index) => DisplayCard (
64- display: displays[index],
65- isSelected: selectedIndex == index,
66- onTap: () => setState (() => selectedIndex = index),
67- ),
25+ return ChangeNotifierProvider <ColorPaletteProvider >(
26+ create: (_) => getIt <ColorPaletteProvider >(),
27+ builder: (context, child) {
28+ return Scaffold (
29+ backgroundColor: Colors .white,
30+ appBar: AppBar (
31+ backgroundColor: colorAccent,
32+ elevation: 0 ,
33+ title: const Padding (
34+ padding: EdgeInsets .fromLTRB (5 , 16 , 16 , 5 ),
35+ child: Column (
36+ crossAxisAlignment: CrossAxisAlignment .start,
37+ children: [
38+ Text ('Magic ePaper' ,
39+ style: TextStyle (
40+ fontSize: 24 ,
41+ fontWeight: FontWeight .bold,
42+ color: Colors .white,
43+ )),
44+ SizedBox (height: 8 ),
45+ Text ('Select your ePaper display type' ,
46+ style: TextStyle (
47+ fontSize: 16 ,
48+ color: Colors .white,
49+ )),
50+ ],
6851 ),
6952 ),
70- _buildContinueButton (context),
71- ],
72- ),
73- ),
74- ),
75- );
53+ toolbarHeight: 85 ,
54+ ),
55+ body: SafeArea (
56+ child: Padding (
57+ padding: const EdgeInsets .fromLTRB (10.0 , 14 , 16.0 , 16.0 ),
58+ child: Column (
59+ children: [
60+ Expanded (
61+ child: GridView .builder (
62+ gridDelegate:
63+ const SliverGridDelegateWithFixedCrossAxisCount (
64+ crossAxisCount: 2 ,
65+ childAspectRatio: 0.6 ,
66+ mainAxisSpacing: 8 ,
67+ crossAxisSpacing: 8 ,
68+ ),
69+ itemCount: displays.length,
70+ itemBuilder: (context, index) => DisplayCard (
71+ display: displays[index],
72+ isSelected: selectedIndex == index,
73+ onTap: () => setState (() => selectedIndex = index),
74+ ),
75+ ),
76+ ),
77+ _buildContinueButton (context),
78+ ],
79+ ),
80+ ),
81+ ),
82+ );
83+ });
7684 }
7785
7886 Widget _buildContinueButton (BuildContext context) {
@@ -83,6 +91,10 @@ class _DisplaySelectionScreenState extends State<DisplaySelectionScreen> {
8391 child: ElevatedButton (
8492 onPressed: isEnabled
8593 ? () {
94+ context.read <ColorPaletteProvider >().updateColors (
95+ displays[selectedIndex].colors,
96+ );
97+
8698 Navigator .push (
8799 context,
88100 MaterialPageRoute (
0 commit comments