|
1 |
| -import 'package:flutter/material.dart'; |
2 |
| -import 'package:weatherbi/Cubit/WeatherState.dart'; |
3 |
| -import 'package:weatherbi/Utils/Constant.dart'; |
4 |
| - |
5 |
| -class Details extends StatefulWidget { |
6 |
| - @override |
7 |
| - _DetailsState createState() => _DetailsState(); |
8 |
| -} |
9 |
| - |
10 |
| -class _DetailsState extends State<Details> { |
11 |
| - @override |
12 |
| - void initState() { |
13 |
| - super.initState(); |
14 |
| - } |
15 |
| - |
16 |
| - @override |
17 |
| - Widget build(BuildContext context) { |
18 |
| - setState(() { |
19 |
| - var weather = ModalRoute.of(context).settings.arguments as Map; |
20 |
| - print(weather['state']); |
21 |
| - }); |
22 |
| - return SafeArea( |
23 |
| - child: Center( |
24 |
| - child: Padding( |
25 |
| - padding: const EdgeInsets.only(top: 8.0), |
26 |
| - child: Column( |
27 |
| - mainAxisAlignment: MainAxisAlignment.spaceBetween, |
28 |
| - children: [ |
29 |
| - buildAppBarTitle(), |
30 |
| - Text( |
31 |
| - "Partly Cloud", |
32 |
| - style: Constant().mainTitle.copyWith(fontWeight: FontWeight.w300, fontSize: 64), |
33 |
| - ), |
34 |
| - Row( |
35 |
| - mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
36 |
| - children: [ |
37 |
| - buildMiddleLeftDesign(), |
38 |
| - Padding( |
39 |
| - padding: const EdgeInsets.only(top: 12), |
40 |
| - child: buildMiddleAllRight(topValue: 28, bottomValue: 17), |
41 |
| - ), |
42 |
| - ], |
43 |
| - ), |
44 |
| - Row( |
45 |
| - mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
46 |
| - children: [ |
47 |
| - buildMiddleAllRight(topValue: 28, bottomValue: "M", isSeen: false), |
48 |
| - buildMiddleAllRight(topValue: 28, bottomValue: "T", isSeen: false), |
49 |
| - buildMiddleAllRight(topValue: 28, bottomValue: "W", isSeen: false), |
50 |
| - buildMiddleAllRight(topValue: 28, bottomValue: "T", isSeen: false), |
51 |
| - buildMiddleAllRight(topValue: 28, bottomValue: "F", isSeen: false), |
52 |
| - buildMiddleAllRight(topValue: 28, bottomValue: "S", isSeen: false), |
53 |
| - buildMiddleAllRight(topValue: 28, bottomValue: "S", isSeen: false), |
54 |
| - ], |
55 |
| - ), |
56 |
| - ], |
57 |
| - ), |
58 |
| - ), |
59 |
| - ), |
60 |
| - ); |
61 |
| - } |
62 |
| - |
63 |
| - Column buildMiddleAllRight({topValue, bottomValue, isSeen = true}) { |
64 |
| - return Column( |
65 |
| - children: [ |
66 |
| - buildMiddleRight(topValue, isSeen: true), |
67 |
| - buildDivider(), |
68 |
| - buildMiddleRight(bottomValue, isSeen: isSeen), |
69 |
| - ], |
70 |
| - ); |
71 |
| - } |
72 |
| - |
73 |
| - Padding buildDivider() { |
74 |
| - return Padding( |
75 |
| - padding: const EdgeInsets.symmetric(vertical: 8.0), |
76 |
| - child: Container( |
77 |
| - width: 55, |
78 |
| - color: Colors.white, |
79 |
| - height: 1, |
80 |
| - ), |
81 |
| - ); |
82 |
| - } |
83 |
| - |
84 |
| - Stack buildMiddleRight(value, {isSeen = true}) { |
85 |
| - return Stack( |
86 |
| - children: [ |
87 |
| - isSeen |
88 |
| - ? Positioned( |
89 |
| - right: 0, |
90 |
| - top: 0, |
91 |
| - child: Container( |
92 |
| - width: 10, |
93 |
| - height: 10, |
94 |
| - decoration: BoxDecoration( |
95 |
| - shape: BoxShape.circle, |
96 |
| - border: Border.all(color: Colors.white, width: 1), |
97 |
| - ), |
98 |
| - ), |
99 |
| - ) |
100 |
| - : Text(""), |
101 |
| - Padding( |
102 |
| - padding: const EdgeInsets.only(right: 10), |
103 |
| - child: Text( |
104 |
| - '$value', |
105 |
| - style: Constant().mainTitle.copyWith(fontWeight: FontWeight.w200, fontSize: 32), |
106 |
| - ), |
107 |
| - ), |
108 |
| - ], |
109 |
| - ); |
110 |
| - } |
111 |
| - |
112 |
| - Column buildMiddleLeftDesign() { |
113 |
| - return Column( |
114 |
| - children: [ |
115 |
| - Stack( |
116 |
| - children: [ |
117 |
| - Positioned( |
118 |
| - right: 0, |
119 |
| - top: 32, |
120 |
| - child: Container( |
121 |
| - width: 25, |
122 |
| - height: 25, |
123 |
| - decoration: BoxDecoration( |
124 |
| - shape: BoxShape.circle, |
125 |
| - border: Border.all(color: Colors.white, width: 3), |
126 |
| - ), |
127 |
| - ), |
128 |
| - ), |
129 |
| - Padding( |
130 |
| - padding: const EdgeInsets.only(right: 32), |
131 |
| - child: Text( |
132 |
| - '23', |
133 |
| - style: Constant().mainTitle.copyWith(fontWeight: FontWeight.w200, fontSize: 128), |
134 |
| - ), |
135 |
| - ), |
136 |
| - ], |
137 |
| - ) |
138 |
| - ], |
139 |
| - ); |
140 |
| - } |
141 |
| - |
142 |
| - Column buildAppBarTitle() { |
143 |
| - return Column( |
144 |
| - children: [ |
145 |
| - Text( |
146 |
| - "Eskişehir", |
147 |
| - style: Constant().mainTitle.copyWith(fontWeight: FontWeight.w300), |
148 |
| - ), |
149 |
| - Text( |
150 |
| - "12:30", |
151 |
| - style: Constant().mainTitle.copyWith(fontWeight: FontWeight.w300, fontSize: 24), |
152 |
| - ), |
153 |
| - ], |
154 |
| - ); |
155 |
| - } |
156 |
| -} |
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:flutter_bloc/flutter_bloc.dart'; |
| 3 | +import 'package:weatherbi/Cubit/WeatherCubit.dart'; |
| 4 | +import 'package:weatherbi/Cubit/WeatherState.dart'; |
| 5 | +import 'package:weatherbi/Utils/Constant.dart'; |
| 6 | + |
| 7 | +class Details extends StatefulWidget { |
| 8 | + @override |
| 9 | + _DetailsState createState() => _DetailsState(); |
| 10 | +} |
| 11 | + |
| 12 | +class _DetailsState extends State<Details> { |
| 13 | + @override |
| 14 | + void initState() { |
| 15 | + super.initState(); |
| 16 | + } |
| 17 | + |
| 18 | + @override |
| 19 | + Widget build(BuildContext context) { |
| 20 | + return BlocConsumer<WeatherCubit, WeatherState>( |
| 21 | + listener: (context, state) { |
| 22 | + if (state is WeatherError) { |
| 23 | + ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(state.message))); |
| 24 | + } |
| 25 | + }, |
| 26 | + builder: (context, state) { |
| 27 | + /* if (state is WeatherInitial) { |
| 28 | + return buildSafeArea(context); |
| 29 | + } */ |
| 30 | + if (state is WeatherLoading) { |
| 31 | + return CircularProgressIndicator(); |
| 32 | + } else if (state is WeatherDone) { |
| 33 | + return buildSafeArea(context, state); |
| 34 | + } else { |
| 35 | + return buildError(state); |
| 36 | + } |
| 37 | + }, |
| 38 | + ); |
| 39 | + } |
| 40 | + |
| 41 | + Text buildError(WeatherState state) { |
| 42 | + final error = state as WeatherError; |
| 43 | + return Text(error.message); |
| 44 | + } |
| 45 | + |
| 46 | + SafeArea buildSafeArea(BuildContext context, WeatherDone state) { |
| 47 | + return SafeArea( |
| 48 | + child: Center( |
| 49 | + child: Padding( |
| 50 | + padding: const EdgeInsets.only(top: 8.0), |
| 51 | + child: Column( |
| 52 | + mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 53 | + children: [ |
| 54 | + buildAppBarTitle(state), |
| 55 | + Text( |
| 56 | + state.weather.current.condition.text, |
| 57 | + style: Constant().mainTitle.copyWith(fontWeight: FontWeight.w300, fontSize: 64), |
| 58 | + ), |
| 59 | + Row( |
| 60 | + mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
| 61 | + children: [ |
| 62 | + buildMiddleLeftDesign(state), |
| 63 | + Padding( |
| 64 | + padding: const EdgeInsets.only(top: 12), |
| 65 | + child: buildMiddleAllRight(topValue: 28, bottomValue: 17), |
| 66 | + ), |
| 67 | + ], |
| 68 | + ), |
| 69 | + Row( |
| 70 | + mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
| 71 | + children: [ |
| 72 | + buildMiddleAllRight(topValue: 28, bottomValue: "M", isSeen: false), |
| 73 | + buildMiddleAllRight(topValue: 28, bottomValue: "T", isSeen: false), |
| 74 | + buildMiddleAllRight(topValue: 28, bottomValue: "W", isSeen: false), |
| 75 | + buildMiddleAllRight(topValue: 28, bottomValue: "T", isSeen: false), |
| 76 | + buildMiddleAllRight(topValue: 28, bottomValue: "F", isSeen: false), |
| 77 | + buildMiddleAllRight(topValue: 28, bottomValue: "S", isSeen: false), |
| 78 | + buildMiddleAllRight(topValue: 28, bottomValue: "S", isSeen: false), |
| 79 | + ], |
| 80 | + ), |
| 81 | + ], |
| 82 | + ), |
| 83 | + ), |
| 84 | + ), |
| 85 | + ); |
| 86 | + } |
| 87 | + |
| 88 | + Column buildMiddleAllRight({topValue, bottomValue, isSeen = true}) { |
| 89 | + return Column( |
| 90 | + children: [ |
| 91 | + buildMiddleRight(topValue, isSeen: true), |
| 92 | + buildDivider(), |
| 93 | + buildMiddleRight(bottomValue, isSeen: isSeen), |
| 94 | + ], |
| 95 | + ); |
| 96 | + } |
| 97 | + |
| 98 | + Padding buildDivider() { |
| 99 | + return Padding( |
| 100 | + padding: const EdgeInsets.symmetric(vertical: 8.0), |
| 101 | + child: Container( |
| 102 | + width: 55, |
| 103 | + color: Colors.white, |
| 104 | + height: 1, |
| 105 | + ), |
| 106 | + ); |
| 107 | + } |
| 108 | + |
| 109 | + Stack buildMiddleRight(value, {isSeen = true}) { |
| 110 | + return Stack( |
| 111 | + children: [ |
| 112 | + isSeen |
| 113 | + ? Positioned( |
| 114 | + right: 0, |
| 115 | + top: 0, |
| 116 | + child: Container( |
| 117 | + width: 10, |
| 118 | + height: 10, |
| 119 | + decoration: BoxDecoration( |
| 120 | + shape: BoxShape.circle, |
| 121 | + border: Border.all(color: Colors.white, width: 1), |
| 122 | + ), |
| 123 | + ), |
| 124 | + ) |
| 125 | + : Text(""), |
| 126 | + Padding( |
| 127 | + padding: const EdgeInsets.only(right: 10), |
| 128 | + child: Text( |
| 129 | + '$value', |
| 130 | + style: Constant().mainTitle.copyWith(fontWeight: FontWeight.w200, fontSize: 32), |
| 131 | + ), |
| 132 | + ), |
| 133 | + ], |
| 134 | + ); |
| 135 | + } |
| 136 | + |
| 137 | + Column buildMiddleLeftDesign(WeatherDone state) { |
| 138 | + return Column( |
| 139 | + children: [ |
| 140 | + Stack( |
| 141 | + children: [ |
| 142 | + Positioned( |
| 143 | + right: 0, |
| 144 | + top: 32, |
| 145 | + child: Container( |
| 146 | + width: 25, |
| 147 | + height: 25, |
| 148 | + decoration: BoxDecoration( |
| 149 | + shape: BoxShape.circle, |
| 150 | + border: Border.all(color: Colors.white, width: 3), |
| 151 | + ), |
| 152 | + ), |
| 153 | + ), |
| 154 | + Padding( |
| 155 | + padding: const EdgeInsets.only(right: 32), |
| 156 | + child: Text( |
| 157 | + state.weather.current.feelslikeC.toString(), |
| 158 | + style: Constant().mainTitle.copyWith(fontWeight: FontWeight.w200, fontSize: 128), |
| 159 | + ), |
| 160 | + ), |
| 161 | + ], |
| 162 | + ) |
| 163 | + ], |
| 164 | + ); |
| 165 | + } |
| 166 | + |
| 167 | + Column buildAppBarTitle(WeatherDone state) { |
| 168 | + return Column( |
| 169 | + children: [ |
| 170 | + Text( |
| 171 | + state.weather.location.name, |
| 172 | + style: Constant().mainTitle.copyWith(fontWeight: FontWeight.w300), |
| 173 | + ), |
| 174 | + Text( |
| 175 | + state.weather.location.localtime, |
| 176 | + style: Constant().mainTitle.copyWith(fontWeight: FontWeight.w300, fontSize: 24), |
| 177 | + ), |
| 178 | + ], |
| 179 | + ); |
| 180 | + } |
| 181 | +} |
0 commit comments