-
Notifications
You must be signed in to change notification settings - Fork 0
/
StepDescription.txt
137 lines (122 loc) · 7.31 KB
/
StepDescription.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
Section 13 - Clima - A Modern Weather App
Task: build a weather app that receives a City and queries a webservice API to get the local weather
1. L-130 - get the location via the phones gps position
1.1 get geolocator package and add to pubspec.yaml, import it into loading_screen
1.2 add func getLocation() that gets loc according to geolocator docs and add async to func!
1.3 change accuracy to "low" (add print to console for testing)
1.4 add permission request to AndroidManifest.xml for Android (in main folder, not debug or profile) and Info.plist for iOS as per GeoLocator instructions in chapter permissions
1.5 call method getLocation when user presses on loading_screen button
2. L-131 - async /await
2.1 create scratchfile: clima_scratch.dart WITHIN CLima-Flutter project (no new scratch file, just new file)
2.2 add code from gist to scratch to simulate first sync, then async only with Futures, then with async /await
3. L-132 - Stateful Widget Lifecycle Methods
3.1 delete content of the scaffold of loading_screen
3.2 update Scaffold so Location is printed to console immediately at loading (initState())
4. L-133 - Exception Handling & Null Aware Operators
4.1 implement a try / catch with margins:
4.1(a) add String var to set margin
4.1(b) add Scaffold with Container with margin & color
4.1(c) add double.parse within try and move Scaffold within try
4.1(d) add catch, copy Scaffold and provide default value of 30 for margin; also print error
4.1(e) simplyfy
4.1(f) if you catch conversion error, provide default for myMarginAsDouble
4.1(g) even simpler - use ?? check for null
4.2 provide try/catch for getLocation() - WITHIN getLocation()!!
5. L-134 - move getLocation() into separate Class
5.1 create class Location in location.dart & cut&paste import geolocator here
5.2 add props longitude & latitude
5.3 add getCurrentLocation & cut&paste try/Catch block from getLocation- needs to return Future<void> to enable getLocation in loading to await as well!!
5.4 assign latitude & longitude
5.5 in loading.dart:
5.5(a) import location.dart
5.5(b) update getLocation to create new Location obj
5.5(c) call getCurrentLocation() - needs await to await results!!
5.5(d) print values of lat & long - don't forget {}!!
6. L-136: Fetching weather data via OpenWeatherMap API
6.1 add http package to pubspec.yaml
6.2 add import http package to loading_screen.dart
6.3 add getData() to loading_screen
7. L-137: JSON Parsing and Dynamic Types
7.1 import dart:convert
7.2 use jsonDecode() to get longitude
7.3 get to weather data (inside obj)
7.4 comment out 7.2 & 7.3
7.5 add temp, condition id, city name
8. L-138: register with openweathermap.org to get API key
8.1 add const apiKey
8.2 replace sample api key with own and change url from samples. to api
8.3 add lat & log variables (a) and assign to lat&long from getLocation (b)
8.4 add long and lat to api url
8.5 move getData() call into getLocation at the end
8.6 refactor getData() into networking.dart
8.6(a) get import http and dart:conversion over
8.6(b) create new class NetworkHelper
8.6(c) in loading_screen combine getLocation and getData
8.6(d) import networking.dart in loading_screen
8.6(e) add NetworkHelper obj
8.6(f) comment out getData and move jsonDecode into getLocationData (also some refactoring with var types
8.6(g) add weatherData that awaits getData from networkHelper
8.6(h) change getData() in networking.dart to return a Future (without <void> !!!)
8.6(i) return decoded json response
8.7 move temperature/condition & cityName to location_screen
9. L-139: Add Spinner to Loading_Screen
9.1 Navigator.push() weatherData from Loading to Location Screen
9.2 add loading indicator to loading screen
9.2(a) get flutter Spinkit package
9.2(b) import spinkit into loading_screen
9.2(c) add spinner to build method
10. L-140: Passing Data to a State Object - getting weatherData into
Pass data through route by adding property to widget:
10.1 add locationWeather prop to LocationScreen class and ad constr
10.2 add prop locationweather set to weatherdata to Location screen call in loading_screen
10.3 add initState() in State class of location screen
10.4 use locationWeather and get Temp, Constitution (id) and City from it -> new method updateUI
10.4(a) add method updateUI to State obj with arg: dynamic weatherData
10.4(b) add vars for temp, condition and city (also changed var of temp/cond& city to double, int and String respectively;
10.4(c) assign weatherData to new vars & remove jsonDecode (handled in networking.dart)
10.4(d) call updateUI with widget.locationWeather in initState()
10.5 change api call to return metric (temp in celsius and not kelvin)
10.6 display temp in location_screen Text widget
10.7 change temperature var to integer to avoid Render Overflow (too many digits)
10.8 refactor loading_screen:
10.8(a) get rid of long/lat vars and replace with loc.longiture & loc.latitude.
11. L-141: Updating the Weather with the WeatherModel
weather.dart includes some code to map condition to icon and some temperature comment-text and icons
11.1 import weather.dart in location-screen
11.2 init WeatherModel
11.3 in updateUI -> getWeatherIcon from WeatherModel
11.4 change condition to a local updateUI var variable and add String WeatherIcon at top
11.5 pass result of getWeatherIcon to weatherIcon var
11.6 add weatherIcon inside Text() widget
11.7 replace comment Text with getMessage()
11.8 wrap code within updateUI in setState()
12. L-142: Refactor Location Methods:
Trigger new location request by tapping on icon -> need to move getLocationData into weather.dart
12.1 move imports for location.dart and networking.dart into weather.dart
12.2 move first part of getLocationData to weather.dart (keep Navigator.push()) into new method: getLocationWeather()
12.3 move api key over
12.4 move first part of url call into const openWeatherMapURL and add this var t NetworkHelper call
12.5 return weatherData from method and change return type to Future<dynamic>
-- in loading_screen:
12.6 import weather.dart
12.7 create new WeatherModel, call getLocationWeather and store in new var weatherData await!
-- on location_screen:
12.8 find Arrow Button, add onPressed() logic, needs await therefore onPressed must by async
12.9 updateUI with weatherdata
12.10 handle if location service doesn't work in updateUI() (before you handle weather data) + empty return
13. L-143: Create & Style a Text Field
And also add logic to "City" button to push to city_screen
-- on location_screen:
13.1 add Navigator.push() to push to city_screen when city icon is clicked (don't forget import)
-- in city_screen:
13.2 add text field widget (props: decoration: filled, fillColor, icon, hintText, border)
13.3 move input decoration into constants file for multiple use
13.4 use onChanged property to get value
14. L-144: Pass Data Backwards through Navigation stack
14.1 Store data from TextField in new String prop cityName
14.2 pass cityName back to location_screen when GetWeather button is pressed
14.2 (a) in city_screen: add Navigator.pop
14.2 (b) in location_screen: add var typedName to Navigator.push to receive - make async!
14.3 in weather.dart: create new method getCityWeather by CityName typed in the cityScreen
14.4 in location_screen: check if typedName is not null, then use getCityWeather & updateUI
14.5 add logic to backbutton in city_screen