This repository was archived by the owner on Mar 26, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +27
-6
lines changed Expand file tree Collapse file tree 2 files changed +27
-6
lines changed Original file line number Diff line number Diff line change 1
1
import 'package:flutter/material.dart' ;
2
+ import 'package:flutter_svg/flutter_svg.dart' ;
2
3
3
4
class WeatherForecast extends StatelessWidget {
4
- const WeatherForecast ({super .key});
5
+ const WeatherForecast ({super .key, this .weatherCondition});
6
+
7
+ final String ? weatherCondition;
5
8
6
9
@override
7
10
Widget build (BuildContext context) {
8
11
final textTheme = Theme .of (context).textTheme;
9
12
10
13
return Column (
11
14
children: [
12
- const AspectRatio (
15
+ AspectRatio (
13
16
aspectRatio: 1 ,
14
- child: Placeholder (),
17
+ child: weatherCondition == null
18
+ ? const Placeholder ()
19
+ : SvgPicture .asset (
20
+ 'images/$weatherCondition .svg' ,
21
+ semanticsLabel: '$weatherCondition image' ,
22
+ ),
15
23
),
16
24
Padding (
17
25
padding: const EdgeInsets .all (16 ),
Original file line number Diff line number Diff line change 1
1
import 'package:flutter/material.dart' ;
2
+ import 'package:flutter_training/model/weather.dart' ;
2
3
import 'package:flutter_training/view/weather_view/component/weather_forecast.dart' ;
3
4
4
- class WeatherPage extends StatelessWidget {
5
+ class WeatherPage extends StatefulWidget {
5
6
const WeatherPage ({super .key});
6
7
8
+ @override
9
+ State <WeatherPage > createState () => _WeatherPageState ();
10
+ }
11
+
12
+ class _WeatherPageState extends State <WeatherPage > {
13
+ final _weather = Weather ();
14
+ String ? _weatherCondition;
15
+
7
16
@override
8
17
Widget build (BuildContext context) {
9
18
return Scaffold (
@@ -13,7 +22,7 @@ class WeatherPage extends StatelessWidget {
13
22
child: Column (
14
23
children: [
15
24
const Spacer (),
16
- const WeatherForecast (),
25
+ WeatherForecast (weatherCondition : _weatherCondition ),
17
26
Flexible (
18
27
child: Column (
19
28
children: [
@@ -31,7 +40,11 @@ class WeatherPage extends StatelessWidget {
31
40
Expanded (
32
41
child: TextButton (
33
42
child: const Text ('Reload' ),
34
- onPressed: () {},
43
+ onPressed: () {
44
+ setState (() {
45
+ _weatherCondition = _weather.fetchWeather ();
46
+ });
47
+ },
35
48
),
36
49
),
37
50
],
You can’t perform that action at this time.
0 commit comments