Skip to content

Commit 3d23fa1

Browse files
authored
Add macos (#13)
1 parent fe745cb commit 3d23fa1

38 files changed

+1736
-76
lines changed

.metadata

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
# This file tracks properties of this Flutter project.
22
# Used by Flutter tool to assess capabilities and perform upgrades etc.
33
#
4-
# This file should be version controlled.
4+
# This file should be version controlled and should not be manually edited.
55

66
version:
7-
revision: 135454af32477f815a7525073027a3ff9eff1bfd
8-
channel: stable
7+
revision: "300451adae589accbece3490f4396f10bdf15e6e"
8+
channel: "stable"
99

1010
project_type: app
1111

1212
# Tracks metadata for the flutter migrate command
1313
migration:
1414
platforms:
1515
- platform: root
16-
create_revision: 135454af32477f815a7525073027a3ff9eff1bfd
17-
base_revision: 135454af32477f815a7525073027a3ff9eff1bfd
18-
- platform: ios
19-
create_revision: 135454af32477f815a7525073027a3ff9eff1bfd
20-
base_revision: 135454af32477f815a7525073027a3ff9eff1bfd
16+
create_revision: 300451adae589accbece3490f4396f10bdf15e6e
17+
base_revision: 300451adae589accbece3490f4396f10bdf15e6e
18+
- platform: macos
19+
create_revision: 300451adae589accbece3490f4396f10bdf15e6e
20+
base_revision: 300451adae589accbece3490f4396f10bdf15e6e
2121

2222
# User provided section
2323

.vscode/launch.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "pulse",
9+
"request": "launch",
10+
"type": "dart"
11+
},
12+
{
13+
"name": "pulse (profile mode)",
14+
"request": "launch",
15+
"type": "dart",
16+
"flutterMode": "profile"
17+
},
18+
{
19+
"name": "pulse (release mode)",
20+
"request": "launch",
21+
"type": "dart",
22+
"flutterMode": "release"
23+
}
24+
]
25+
}

lib/src/app/app.dart

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:io';
12
import 'dart:ui';
23

34
import 'package:flutter/material.dart';
@@ -7,6 +8,7 @@ import 'package:yaru/yaru.dart';
78

89
import '../../constants.dart';
910
import '../../weather.dart';
11+
import '../build_context_x.dart';
1012
import '../l10n/l10n.dart';
1113
import '../weather/weather_model.dart';
1214
import 'side_bar.dart';
@@ -70,25 +72,27 @@ class _AppPageState extends State<AppPage> {
7072

7173
return LayoutBuilder(
7274
builder: (context, constraints) {
75+
var list = [
76+
if (constraints.maxWidth > kBreakPoint) const SideBar(),
77+
Expanded(
78+
child: WeatherPage(
79+
showDrawer: constraints.maxWidth < kBreakPoint,
80+
),
81+
),
82+
];
7383
return Stack(
84+
alignment: Alignment.center,
7485
children: [
7586
Opacity(
76-
opacity: 0.7,
87+
opacity: Platform.isMacOS ? (context.light ? 1 : 0.6) : 0.7,
7788
child: WeatherBg(
7889
weatherType: weatherType,
7990
width: constraints.maxWidth,
8091
height: constraints.maxHeight,
8192
),
8293
),
8394
Row(
84-
children: [
85-
if (constraints.maxWidth > kBreakPoint) const SideBar(),
86-
Expanded(
87-
child: WeatherPage(
88-
showDrawer: constraints.maxWidth < kBreakPoint,
89-
),
90-
),
91-
],
95+
children: Platform.isMacOS ? list.reversed.toList() : list,
9296
),
9397
],
9498
);

lib/src/app/side_bar.dart

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,24 @@ class SideBar extends StatelessWidget with WatchItMixin {
2727
itemCount: favLocationsLength,
2828
itemBuilder: (context, index) {
2929
final location = favLocations.elementAt(index);
30-
return YaruMasterTile(
31-
onTap: () {
32-
model.loadWeather(cityName: location);
33-
onSelected?.call();
34-
},
35-
selected: lastLocation == location,
36-
title: Text(
37-
favLocations.elementAt(index),
38-
),
39-
trailing: favLocationsLength > 1
40-
? Center(
41-
widthFactor: 0.1,
30+
return Stack(
31+
alignment: Alignment.centerRight,
32+
children: [
33+
YaruMasterTile(
34+
onTap: () {
35+
model.loadWeather(cityName: location);
36+
onSelected?.call();
37+
},
38+
selected: lastLocation == location,
39+
title: Text(
40+
favLocations.elementAt(index),
41+
),
42+
),
43+
if (favLocationsLength > 1 && lastLocation == location)
44+
Positioned(
45+
right: 20,
46+
child: SizedBox.square(
47+
dimension: 30,
4248
child: IconButton(
4349
padding: EdgeInsets.zero,
4450
onPressed: () {
@@ -52,8 +58,9 @@ class SideBar extends StatelessWidget with WatchItMixin {
5258
YaruIcons.window_close,
5359
),
5460
),
55-
)
56-
: null,
61+
),
62+
),
63+
],
5764
);
5865
},
5966
);

lib/src/weather/view/city_search_field.dart

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class _CitySearchFieldState extends State<CitySearchField> {
3838
Widget build(BuildContext context) {
3939
final model = di<WeatherModel>();
4040
final error = watchPropertyValue((WeatherModel m) => m.error);
41+
final loading = watchPropertyValue((WeatherModel m) => m.loading);
42+
4143
final theme = context.theme;
4244
var textField = TextField(
4345
autofocus: true,
@@ -76,26 +78,23 @@ class _CitySearchFieldState extends State<CitySearchField> {
7678
: null,
7779
errorMaxLines: 10,
7880
suffixIconConstraints: const BoxConstraints(
79-
maxHeight: kYaruTitleBarItemHeight,
80-
minHeight: kYaruTitleBarItemHeight,
81-
minWidth: kYaruTitleBarItemHeight,
82-
maxWidth: kYaruTitleBarItemHeight,
81+
maxHeight: 20,
82+
minHeight: 20,
83+
minWidth: 20,
84+
maxWidth: 20,
8385
),
84-
// suffixIcon: ClipRRect(
85-
// borderRadius: const BorderRadius.only(
86-
// topRight: Radius.circular(kYaruButtonRadius),
87-
// bottomRight: Radius.circular(kYaruButtonRadius),
88-
// ),
89-
// child: Material(
90-
// color: Colors.transparent,
91-
// child: InkWell(
92-
// child: const Icon(
93-
// YaruIcons.location,
94-
// ),
95-
// onTap: () => model.init(cityName: null),
96-
// ),
97-
// ),
98-
// ),
86+
suffixIcon: (loading)
87+
? Padding(
88+
padding: const EdgeInsets.only(right: 8),
89+
child: SizedBox.square(
90+
dimension: 20,
91+
child: YaruCircularProgressIndicator(
92+
color: context.theme.colorScheme.onSurface,
93+
strokeWidth: 1,
94+
),
95+
),
96+
)
97+
: null,
9998
),
10099
);
101100
return textField;

lib/src/weather/view/hourly_line_chart.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,12 @@ class _HourlyLineChartState extends State<HourlyLineChart> {
219219
),
220220
minX: 0,
221221
maxX: (forecast.length - 1).toDouble(),
222-
minY: forecast.map((e) => e.temperature.currentTemperature).min,
223-
maxY: forecast.map((e) => e.temperature.currentTemperature).max,
222+
minY: forecast.isEmpty
223+
? 10
224+
: forecast.map((e) => e.temperature.currentTemperature).min,
225+
maxY: forecast.isEmpty
226+
? 100
227+
: forecast.map((e) => e.temperature.currentTemperature).max,
224228
lineBarsData: [
225229
LineChartBarData(
226230
spots: forecast

lib/src/weather/view/weather_page.dart

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:io';
2+
13
import 'package:flutter/material.dart';
24
import 'package:watch_it/watch_it.dart';
35
import 'package:yaru/yaru.dart';
@@ -23,29 +25,22 @@ class WeatherPage extends StatelessWidget with WatchItMixin {
2325
initialIndex: appModel.tabIndex,
2426
length: 2,
2527
child: Scaffold(
26-
drawer: Drawer(
27-
child: Builder(
28-
builder: (context) {
29-
return SideBar(
30-
onSelected: () => Scaffold.of(context).closeDrawer(),
31-
);
32-
},
33-
),
34-
),
28+
drawer: Platform.isMacOS ? null : const _Drawer(),
29+
endDrawer: Platform.isMacOS ? const _Drawer() : null,
3530
backgroundColor: Colors.transparent,
3631
appBar: YaruWindowTitleBar(
37-
leading: showDrawer
38-
? Builder(
39-
builder: (context) {
40-
return Center(
41-
child: IconButton(
42-
onPressed: () => Scaffold.of(context).openDrawer(),
43-
icon: const Icon(YaruIcons.menu),
44-
),
45-
);
46-
},
47-
)
48-
: null,
32+
leading: Platform.isMacOS
33+
? null
34+
: showDrawer
35+
? const _DrawerButton()
36+
: null,
37+
actions: [
38+
if (Platform.isMacOS && showDrawer)
39+
const Padding(
40+
padding: EdgeInsets.only(right: 8),
41+
child: _DrawerButton(),
42+
),
43+
],
4944
backgroundColor: Colors.transparent,
5045
border: BorderSide.none,
5146
title: SizedBox(
@@ -64,3 +59,50 @@ class WeatherPage extends StatelessWidget with WatchItMixin {
6459
);
6560
}
6661
}
62+
63+
class _DrawerButton extends StatelessWidget {
64+
const _DrawerButton();
65+
66+
@override
67+
Widget build(BuildContext context) {
68+
return Builder(
69+
builder: (context) {
70+
return Center(
71+
child: IconButton(
72+
onPressed: () {
73+
if (Platform.isMacOS) {
74+
Scaffold.of(context).openEndDrawer();
75+
} else {
76+
Scaffold.of(context).openDrawer();
77+
}
78+
},
79+
icon: const Icon(YaruIcons.menu),
80+
),
81+
);
82+
},
83+
);
84+
}
85+
}
86+
87+
class _Drawer extends StatelessWidget {
88+
const _Drawer();
89+
90+
@override
91+
Widget build(BuildContext context) {
92+
return Drawer(
93+
child: Builder(
94+
builder: (context) {
95+
return SideBar(
96+
onSelected: () {
97+
if (Platform.isMacOS) {
98+
Scaffold.of(context).closeEndDrawer();
99+
} else {
100+
Scaffold.of(context).closeDrawer();
101+
}
102+
},
103+
);
104+
},
105+
),
106+
);
107+
}
108+
}

lib/src/weather/weather_model.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,17 @@ class WeatherModel extends SafeChangeNotifier {
5151
notifyListeners();
5252
}
5353

54+
bool _loading = false;
55+
bool get loading => _loading;
56+
set loading(bool value) {
57+
if (value == _loading) return;
58+
_loading = value;
59+
notifyListeners();
60+
}
61+
5462
Future<void> loadWeather({String? cityName}) async {
55-
_weatherData = null;
5663
_error = null;
57-
notifyListeners();
64+
loading = true;
5865

5966
cityName ??= lastLocation ?? '';
6067

@@ -77,7 +84,7 @@ class WeatherModel extends SafeChangeNotifier {
7784
_weatherType = _weatherData!.weatherType;
7885
}
7986

80-
notifyListeners();
87+
loading = false;
8188
}
8289

8390
@override

macos/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Flutter-related
2+
**/Flutter/ephemeral/
3+
**/Pods/
4+
5+
# Xcode-related
6+
**/dgph
7+
**/xcuserdata/
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
2+
#include "ephemeral/Flutter-Generated.xcconfig"

0 commit comments

Comments
 (0)