|
1 | | -import 'package:day35/animation/FadeAnimation.dart'; |
2 | | -import 'package:day35/models/service.dart'; |
3 | | -import 'package:day35/pages/cleaning.dart'; |
| 1 | +import 'package:day35/pages/home.dart'; |
| 2 | +import 'package:day35/pages/select_service.dart'; |
4 | 3 | import 'package:flutter/material.dart';
|
5 | 4 |
|
6 | 5 | void main () {
|
7 | 6 | runApp(MaterialApp(
|
8 | | - home: HomePage(), |
| 7 | + home: SelectService(), |
9 | 8 | debugShowCheckedModeBanner: false,
|
10 | 9 | ));
|
11 | 10 | }
|
12 | | - |
13 | | -class HomePage extends StatefulWidget { |
14 | | - const HomePage({ Key? key }) : super(key: key); |
15 | | - |
16 | | - @override |
17 | | - _HomePageState createState() => _HomePageState(); |
18 | | -} |
19 | | - |
20 | | -class _HomePageState extends State<HomePage> { |
21 | | - List<Service> services = [ |
22 | | - Service('Cleaning', 'https://img.icons8.com/external-vitaliy-gorbachev-flat-vitaly-gorbachev/2x/external-cleaning-labour-day-vitaliy-gorbachev-flat-vitaly-gorbachev.png'), |
23 | | - Service('Plumber', 'https://img.icons8.com/external-vitaliy-gorbachev-flat-vitaly-gorbachev/2x/external-plumber-labour-day-vitaliy-gorbachev-flat-vitaly-gorbachev.png'), |
24 | | - Service('Electrician', 'https://img.icons8.com/external-wanicon-flat-wanicon/2x/external-multimeter-car-service-wanicon-flat-wanicon.png'), |
25 | | - Service('Painter', 'https://img.icons8.com/external-itim2101-flat-itim2101/2x/external-painter-male-occupation-avatar-itim2101-flat-itim2101.png'), |
26 | | - Service('Carpenter', 'https://img.icons8.com/fluency/2x/drill.png'), |
27 | | - Service('Gardener', 'https://img.icons8.com/external-itim2101-flat-itim2101/2x/external-gardener-male-occupation-avatar-itim2101-flat-itim2101.png'), |
28 | | - Service('Tailor', 'https://img.icons8.com/fluency/2x/sewing-machine.png'), |
29 | | - Service('Maid', 'https://img.icons8.com/color/2x/housekeeper-female.png'), |
30 | | - Service('Driver', 'https://img.icons8.com/external-sbts2018-lineal-color-sbts2018/2x/external-driver-women-profession-sbts2018-lineal-color-sbts2018.png'), |
31 | | - Service('Cook', 'https://img.icons8.com/external-wanicon-flat-wanicon/2x/external-cooking-daily-routine-wanicon-flat-wanicon.png'), |
32 | | - ]; |
33 | | - |
34 | | - int selectedService = -1; |
35 | | - |
36 | | - @override |
37 | | - Widget build(BuildContext context) { |
38 | | - return Scaffold( |
39 | | - backgroundColor: Colors.white, |
40 | | - floatingActionButton: selectedService >= 0 ? FloatingActionButton( |
41 | | - onPressed: () { |
42 | | - Navigator.push( |
43 | | - context, |
44 | | - MaterialPageRoute( |
45 | | - builder: (context) => CleaningPage(), |
46 | | - ), |
47 | | - ); |
48 | | - }, |
49 | | - child: Icon(Icons.arrow_forward_ios, size: 20,), |
50 | | - backgroundColor: Colors.blue, |
51 | | - ) : null, |
52 | | - body: NestedScrollView( |
53 | | - headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { |
54 | | - return <Widget>[ |
55 | | - SliverToBoxAdapter( |
56 | | - child: FadeAnimation(1.2, Padding( |
57 | | - padding: EdgeInsets.only(top: 120.0, right: 20.0, left: 20.0), |
58 | | - child: Text( |
59 | | - 'Which service \ndo you need?', |
60 | | - style: TextStyle( |
61 | | - fontSize: 40, |
62 | | - color: Colors.grey.shade900, |
63 | | - fontWeight: FontWeight.bold, |
64 | | - ), |
65 | | - ), |
66 | | - ), |
67 | | - )) |
68 | | - ]; |
69 | | - }, |
70 | | - body: Padding( |
71 | | - padding: EdgeInsets.all(20.0), |
72 | | - child: Column( |
73 | | - crossAxisAlignment: CrossAxisAlignment.start, |
74 | | - children: <Widget>[ |
75 | | - Expanded( |
76 | | - child: GridView.builder( |
77 | | - gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( |
78 | | - crossAxisCount: 2, |
79 | | - childAspectRatio: 1.0, |
80 | | - crossAxisSpacing: 20.0, |
81 | | - mainAxisSpacing: 20.0, |
82 | | - ), |
83 | | - physics: NeverScrollableScrollPhysics(), |
84 | | - itemCount: services.length, |
85 | | - itemBuilder: (BuildContext context, int index) { |
86 | | - return FadeAnimation((1.0 + index) / 4, serviceContainer(services[index].imageURL, services[index].name, index)); |
87 | | - } |
88 | | - ), |
89 | | - ), |
90 | | - ] |
91 | | - ), |
92 | | - ), |
93 | | - ) |
94 | | - ); |
95 | | - } |
96 | | - |
97 | | - serviceContainer(String image, String name, int index) { |
98 | | - return GestureDetector( |
99 | | - onTap: () { |
100 | | - setState(() { |
101 | | - if (selectedService == index) |
102 | | - selectedService = -1; |
103 | | - else |
104 | | - selectedService = index; |
105 | | - }); |
106 | | - }, |
107 | | - child: AnimatedContainer( |
108 | | - duration: Duration(milliseconds: 300), |
109 | | - padding: EdgeInsets.all(10.0), |
110 | | - decoration: BoxDecoration( |
111 | | - color: selectedService == index ? Colors.blue.shade50 : Colors.grey.shade100, |
112 | | - border: Border.all( |
113 | | - color: selectedService == index ? Colors.blue : Colors.blue.withOpacity(0), |
114 | | - width: 2.0, |
115 | | - ), |
116 | | - borderRadius: BorderRadius.circular(20.0), |
117 | | - ), |
118 | | - child: Column( |
119 | | - mainAxisAlignment: MainAxisAlignment.center, |
120 | | - children: <Widget>[ |
121 | | - Image.network(image, height: 80), |
122 | | - SizedBox(height: 20,), |
123 | | - Text(name, style: TextStyle(fontSize: 20),) |
124 | | - ] |
125 | | - ), |
126 | | - ), |
127 | | - ); |
128 | | - } |
129 | | -} |
0 commit comments