|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:drinks_selection_screen/widgets/image_carousel.dart'; |
| 3 | +import 'package:drinks_selection_screen/widgets/logo_widget.dart'; |
| 4 | +import 'data.dart'; |
| 5 | + |
| 6 | +class HomeScreen extends StatefulWidget { |
| 7 | + const HomeScreen({super.key}); |
| 8 | + |
| 9 | + @override |
| 10 | + State<HomeScreen> createState() => _HomeScreenState(); |
| 11 | +} |
| 12 | + |
| 13 | +class _HomeScreenState extends State<HomeScreen> { |
| 14 | + final PageController _pageController = PageController(); |
| 15 | + Color _backgroundColor = const Color(0xffb71c1c); |
| 16 | + |
| 17 | + void _onPageChanged(int index) { |
| 18 | + setState(() { |
| 19 | + _backgroundColor = coffeeList[index].backgroundColor; |
| 20 | + _pageController.animateToPage( |
| 21 | + index, |
| 22 | + duration: const Duration(milliseconds: 500), |
| 23 | + curve: Curves.easeOutQuad, |
| 24 | + ); |
| 25 | + }); |
| 26 | + } |
| 27 | + |
| 28 | + @override |
| 29 | + Widget build(BuildContext context) { |
| 30 | + return Scaffold( |
| 31 | + backgroundColor: const Color(0xfff5f5f5), |
| 32 | + body: Stack( |
| 33 | + children: [ |
| 34 | + AnimatedContainer( |
| 35 | + duration: const Duration(milliseconds: 500), |
| 36 | + decoration: BoxDecoration( |
| 37 | + gradient: LinearGradient( |
| 38 | + begin: Alignment.topLeft, |
| 39 | + end: Alignment.bottomRight, |
| 40 | + colors: [_backgroundColor, Colors.redAccent], |
| 41 | + ), |
| 42 | + ), |
| 43 | + child: Stack( |
| 44 | + children: [ |
| 45 | + Center( |
| 46 | + child: Container( |
| 47 | + height: 250, |
| 48 | + width: 250, |
| 49 | + decoration: BoxDecoration( |
| 50 | + shape: BoxShape.circle, |
| 51 | + boxShadow: [ |
| 52 | + BoxShadow( |
| 53 | + color: Colors.redAccent.withOpacity(0.3), |
| 54 | + blurRadius: 120, |
| 55 | + spreadRadius: 20, |
| 56 | + ), |
| 57 | + ], |
| 58 | + ), |
| 59 | + ), |
| 60 | + ), |
| 61 | + Scaffold( |
| 62 | + backgroundColor: Colors.transparent, |
| 63 | + body: Padding( |
| 64 | + padding: const EdgeInsets.all(15), |
| 65 | + child: Column( |
| 66 | + mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 67 | + children: [ |
| 68 | + const LogoWidget(), |
| 69 | + _buildCoffeeList(), |
| 70 | + ], |
| 71 | + ), |
| 72 | + ), |
| 73 | + ), |
| 74 | + ], |
| 75 | + ), |
| 76 | + ), |
| 77 | + CustomImageCarousel( |
| 78 | + onPageChange: _onPageChanged, |
| 79 | + ), |
| 80 | + ], |
| 81 | + ), |
| 82 | + ); |
| 83 | + } |
| 84 | + |
| 85 | + Widget _buildCoffeeList() { |
| 86 | + return Container( |
| 87 | + height: 380, |
| 88 | + width: double.infinity, |
| 89 | + margin: const EdgeInsets.all(10), |
| 90 | + decoration: BoxDecoration( |
| 91 | + borderRadius: BorderRadius.circular(25), |
| 92 | + color: Colors.white, |
| 93 | + boxShadow: const [ |
| 94 | + BoxShadow( |
| 95 | + color: Color(0x33000000), |
| 96 | + blurRadius: 20, |
| 97 | + spreadRadius: 2, |
| 98 | + ), |
| 99 | + ], |
| 100 | + ), |
| 101 | + padding: const EdgeInsets.all(20), |
| 102 | + child: Column( |
| 103 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 104 | + children: [ |
| 105 | + const SizedBox(height: 25), |
| 106 | + Expanded( |
| 107 | + child: PageView.builder( |
| 108 | + controller: _pageController, |
| 109 | + scrollDirection: Axis.vertical, |
| 110 | + physics: const NeverScrollableScrollPhysics(), |
| 111 | + itemCount: coffeeList.length, |
| 112 | + itemBuilder: (context, index) { |
| 113 | + final coffee = coffeeList[index]; |
| 114 | + return Column( |
| 115 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 116 | + children: [ |
| 117 | + RichText( |
| 118 | + text: TextSpan( |
| 119 | + children: [ |
| 120 | + TextSpan( |
| 121 | + text: 'Giá: ', |
| 122 | + style: TextStyle( |
| 123 | + color: Colors.white, |
| 124 | + fontSize: 20, |
| 125 | + fontWeight: FontWeight.w400, |
| 126 | + shadows: [ |
| 127 | + Shadow( |
| 128 | + blurRadius: 5.0, |
| 129 | + color: Colors.black.withOpacity(0.9), |
| 130 | + offset: const Offset(1.0, 1.0), |
| 131 | + ), |
| 132 | + ], |
| 133 | + ), |
| 134 | + ), |
| 135 | + TextSpan( |
| 136 | + text: ' ${coffee.price} ', |
| 137 | + style: const TextStyle( |
| 138 | + color: Colors.black, |
| 139 | + fontWeight: FontWeight.bold, |
| 140 | + fontSize: 28, |
| 141 | + ), |
| 142 | + ), |
| 143 | + const TextSpan( |
| 144 | + text: 'đ', |
| 145 | + style: TextStyle( |
| 146 | + color: Colors.black, |
| 147 | + fontWeight: FontWeight.bold, |
| 148 | + fontSize: 25, |
| 149 | + ), |
| 150 | + ), |
| 151 | + ], |
| 152 | + ), |
| 153 | + ), |
| 154 | + const SizedBox(height: 20), |
| 155 | + Text( |
| 156 | + coffee.title, |
| 157 | + style: const TextStyle( |
| 158 | + fontSize: 24, |
| 159 | + fontWeight: FontWeight.bold, |
| 160 | + color: Color(0xffd32f2f), |
| 161 | + ), |
| 162 | + ), |
| 163 | + const SizedBox(height: 20), |
| 164 | + Text( |
| 165 | + coffee.description, |
| 166 | + style: const TextStyle( |
| 167 | + fontSize: 16, |
| 168 | + color: Colors.black87, |
| 169 | + ), |
| 170 | + maxLines: 4, |
| 171 | + overflow: TextOverflow.ellipsis, |
| 172 | + ), |
| 173 | + ], |
| 174 | + ); |
| 175 | + }, |
| 176 | + ), |
| 177 | + ), |
| 178 | + _buildOrderButton(), |
| 179 | + ], |
| 180 | + ), |
| 181 | + ); |
| 182 | + } |
| 183 | + |
| 184 | + Widget _buildOrderButton() { |
| 185 | + return Container( |
| 186 | + height: 55, |
| 187 | + width: double.infinity, |
| 188 | + decoration: BoxDecoration( |
| 189 | + borderRadius: BorderRadius.circular(30), |
| 190 | + gradient: const LinearGradient( |
| 191 | + colors: [ |
| 192 | + Color(0xffb71c1c), |
| 193 | + Color(0xff000000), |
| 194 | + Color(0xfff44336), |
| 195 | + ], |
| 196 | + begin: Alignment.topLeft, |
| 197 | + end: Alignment.bottomRight, |
| 198 | + ), |
| 199 | + boxShadow: const [ |
| 200 | + BoxShadow( |
| 201 | + color: Color(0x30000000), |
| 202 | + blurRadius: 30, |
| 203 | + spreadRadius: 5, |
| 204 | + offset: Offset(10, 10), |
| 205 | + ), |
| 206 | + ], |
| 207 | + ), |
| 208 | + alignment: Alignment.center, |
| 209 | + child: const Text( |
| 210 | + "ĐẶT NGAY", |
| 211 | + style: TextStyle( |
| 212 | + color: Colors.white, |
| 213 | + fontWeight: FontWeight.w800, |
| 214 | + fontSize: 18, |
| 215 | + ), |
| 216 | + ), |
| 217 | + ); |
| 218 | + } |
| 219 | +} |
0 commit comments