11import 'dart:ui' ;
22
33import 'package:flutter/material.dart' ;
4+ import 'package:flutter_weather_bg_null_safety/bg/weather_bg.dart' ;
45import 'package:watch_it/watch_it.dart' ;
56import 'package:yaru/yaru.dart' ;
67
8+ import '../../build_context_x.dart' ;
79import '../../constants.dart' ;
810import '../../weather.dart' ;
911import '../weather/view/city_search_field.dart' ;
1012import '../weather/weather_model.dart' ;
13+ import '../weather/weather_utils.dart' ;
1114import 'app_model.dart' ;
1215import 'offline_page.dart' ;
1316
@@ -19,9 +22,9 @@ class App extends StatelessWidget {
1922 return MaterialApp (
2023 title: 'Weather' ,
2124 debugShowCheckedModeBanner: false ,
22- theme : yaruLight ,
25+ themeMode : ThemeMode .dark ,
2326 darkTheme: yaruDark,
24- home: const MasterDetailPage (),
27+ home: const AppPage (),
2528 scrollBehavior: const MaterialScrollBehavior ().copyWith (
2629 dragDevices: {
2730 PointerDeviceKind .mouse,
@@ -35,30 +38,42 @@ class App extends StatelessWidget {
3538 }
3639}
3740
38- class MasterDetailPage extends StatelessWidget with WatchItMixin {
39- const MasterDetailPage ({super .key});
41+ class AppPage extends StatefulWidget with WatchItStatefulWidgetMixin {
42+ const AppPage ({super .key});
43+
44+ @override
45+ State <AppPage > createState () => _AppPageState ();
46+ }
47+
48+ class _AppPageState extends State <AppPage > {
49+ @override
50+ void initState () {
51+ final lastLocation = di <WeatherModel >().lastLocation;
52+ if (lastLocation != null ) {
53+ di <WeatherModel >().loadWeather (cityName: lastLocation);
54+ }
55+ super .initState ();
56+ }
4057
4158 @override
4259 Widget build (BuildContext context) {
4360 final isOnline = watchPropertyValue ((AppModel m) => m.isOnline);
44- if (! isOnline) {
45- return const OfflinePage ();
46- }
61+
4762 final model = di <WeatherModel >();
63+ final mq = context.mq;
64+ final theme = context.theme;
65+ final data = watchPropertyValue ((WeatherModel m) => m.data);
4866 final favLocationsLength =
4967 watchPropertyValue ((WeatherModel m) => m.favLocations.length);
5068 final favLocations = watchPropertyValue ((WeatherModel m) => m.favLocations);
5169 final lastLocation = watchPropertyValue ((WeatherModel m) => m.lastLocation);
52- return YaruMasterDetailPage (
53- controller: YaruPageController (
54- length: favLocationsLength == 0 ? 1 : favLocationsLength,
55- ),
56- layoutDelegate: const YaruMasterFixedPaneDelegate (paneWidth: kPaneWidth),
57- tileBuilder: (context, index, selected, availableWidth) {
70+
71+ final listView = ListView .builder (
72+ itemCount: favLocationsLength,
73+ itemBuilder: (context, index) {
5874 final location = favLocations.elementAt (index);
5975 return YaruMasterTile (
60- // TODO: assign pages to location
61- onTap: () => model.init (cityName: location),
76+ onTap: () => model.loadWeather (cityName: location),
6277 selected: lastLocation == location,
6378 title: Text (
6479 favLocations.elementAt (index),
@@ -70,7 +85,7 @@ class MasterDetailPage extends StatelessWidget with WatchItMixin {
7085 padding: EdgeInsets .zero,
7186 onPressed: () {
7287 model.removeFavLocation (location).then (
73- (value) => model.init (
88+ (value) => model.loadWeather (
7489 cityName: favLocations.lastOrNull,
7590 ),
7691 );
@@ -83,15 +98,49 @@ class MasterDetailPage extends StatelessWidget with WatchItMixin {
8398 : null ,
8499 );
85100 },
86- pageBuilder: (context, index) {
87- return const WeatherPage ();
88- },
89- appBar: YaruDialogTitleBar (
90- backgroundColor: YaruMasterDetailTheme .of (context).sideBarColor,
91- border: BorderSide .none,
92- style: YaruTitleBarStyle .undecorated,
93- title: const CitySearchField (),
94- ),
101+ );
102+
103+ return Stack (
104+ children: [
105+ if (data != null )
106+ Opacity (
107+ opacity: 0.6 ,
108+ child: WeatherBg (
109+ weatherType: getWeatherType (data),
110+ width: mq.size.width,
111+ height: mq.size.height,
112+ ),
113+ ),
114+ Row (
115+ children: [
116+ Material (
117+ color: theme.colorScheme.surface.withOpacity (0.4 ),
118+ child: SizedBox (
119+ width: kPaneWidth,
120+ child: Column (
121+ children: [
122+ const YaruDialogTitleBar (
123+ shape: RoundedRectangleBorder (
124+ borderRadius: BorderRadius .only (
125+ topLeft: Radius .circular (kYaruContainerRadius),
126+ ),
127+ ),
128+ backgroundColor: Colors .transparent,
129+ border: BorderSide .none,
130+ style: YaruTitleBarStyle .undecorated,
131+ title: CitySearchField (),
132+ ),
133+ Expanded (child: listView),
134+ ],
135+ ),
136+ ),
137+ ),
138+ Expanded (
139+ child: ! isOnline ? const OfflinePage () : const WeatherPage (),
140+ ),
141+ ],
142+ ),
143+ ],
95144 );
96145 }
97146}
0 commit comments