Skip to content

Commit bf7e2e8

Browse files
committed
Move platform check to helper
Also, use TargetPlatform since it it better suited for tests (and seems to be now the recommended way of checking this for UI elements)
1 parent fe957e4 commit bf7e2e8

File tree

7 files changed

+119
-101
lines changed

7 files changed

+119
-101
lines changed

lib/helpers/platform.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* This file is part of wger Workout Manager <https://github.com/wger-project>.
3+
* Copyright (C) 2020, 2021 wger Team
4+
*
5+
* wger Workout Manager is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* wger Workout Manager is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
import 'package:flutter/foundation.dart';
20+
21+
// Note: we're not using Platform.isAndroid etc because during tests these would+
22+
// always take the value of the current platform. TargetPlatform is always Android
23+
// during tests, but can be changed to check for correct UI switches, etc.
24+
final isDesktop = [TargetPlatform.linux, TargetPlatform.macOS].contains(defaultTargetPlatform);

lib/screens/gallery_screen.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
import 'dart:io';
20-
2119
import 'package:flutter/material.dart';
2220
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
2321
import 'package:provider/provider.dart';
22+
import 'package:wger/helpers/platform.dart';
2423
import 'package:wger/providers/gallery.dart';
2524
import 'package:wger/widgets/core/app_bar.dart';
2625
import 'package:wger/widgets/gallery/forms.dart';
@@ -37,7 +36,7 @@ class GalleryScreen extends StatelessWidget {
3736
Widget build(BuildContext context) {
3837
return Scaffold(
3938
appBar: EmptyAppBar(AppLocalizations.of(context).gallery),
40-
floatingActionButton: (Platform.isLinux || Platform.isMacOS)
39+
floatingActionButton: isDesktop
4140
? null
4241
: FloatingActionButton(
4342
child: const Icon(Icons.add),

lib/widgets/exercises/exercises.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
import 'dart:io';
20-
2119
import 'package:flutter/material.dart';
2220
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
2321
import 'package:flutter_html/flutter_html.dart';
2422
import 'package:flutter_svg/svg.dart';
2523
import 'package:provider/provider.dart';
2624
import 'package:wger/helpers/consts.dart';
2725
import 'package:wger/helpers/i18n.dart';
26+
import 'package:wger/helpers/platform.dart';
2827
import 'package:wger/models/exercises/base.dart';
2928
import 'package:wger/models/exercises/muscle.dart';
3029
import 'package:wger/models/exercises/translation.dart';
@@ -219,7 +218,7 @@ class ExerciseDetail extends StatelessWidget {
219218
List<Widget> getVideos() {
220219
// TODO: add carousel for the other videos
221220
final List<Widget> out = [];
222-
if (_exerciseBase.videos.isNotEmpty && !(Platform.isLinux || Platform.isMacOS)) {
221+
if (_exerciseBase.videos.isNotEmpty && !isDesktop) {
223222
_exerciseBase.videos.map((v) => ExerciseVideoWidget(video: v)).forEach((element) {
224223
out.add(element);
225224
});

lib/widgets/gallery/overview.dart

Lines changed: 67 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
import 'dart:io';
20-
2119
import 'package:flutter/material.dart';
2220
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
2321
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
2422
import 'package:intl/intl.dart';
2523
import 'package:provider/provider.dart';
24+
import 'package:wger/helpers/platform.dart';
2625
import 'package:wger/providers/gallery.dart';
2726
import 'package:wger/screens/form_screen.dart';
2827

@@ -40,76 +39,76 @@ class Gallery extends StatelessWidget {
4039
child: RefreshIndicator(
4140
onRefresh: () => provider.fetchAndSetGallery(),
4241
child: MasonryGridView.count(
43-
crossAxisCount: 2,
44-
mainAxisSpacing: 5,
45-
crossAxisSpacing: 5,
46-
itemCount: provider.images.length,
47-
itemBuilder: (context, index) {
48-
final currentImage = provider.images[index];
42+
crossAxisCount: 2,
43+
mainAxisSpacing: 5,
44+
crossAxisSpacing: 5,
45+
itemCount: provider.images.length,
46+
itemBuilder: (context, index) {
47+
final currentImage = provider.images[index];
4948

50-
return GestureDetector(
51-
onTap: () {
52-
showModalBottomSheet(
53-
builder: (context) => Material(
54-
child: Container(
55-
key: Key('image-${currentImage.id}-detail'),
56-
padding: const EdgeInsets.all(10),
57-
color: Colors.white,
58-
child: Column(
49+
return GestureDetector(
50+
onTap: () {
51+
showModalBottomSheet(
52+
builder: (context) => Container(
53+
key: Key('image-${currentImage.id}-detail'),
54+
padding: const EdgeInsets.all(10),
55+
color: Colors.white,
56+
child: Column(
57+
children: [
58+
Text(
59+
DateFormat.yMd(Localizations.localeOf(context).languageCode)
60+
.format(currentImage.date),
61+
style: Theme.of(context).textTheme.headline5,
62+
),
63+
Expanded(
64+
child: Image.network(currentImage.url!),
65+
),
66+
Padding(
67+
padding: const EdgeInsets.symmetric(vertical: 8),
68+
child: Text(currentImage.description),
69+
),
70+
Row(
71+
mainAxisAlignment: MainAxisAlignment.center,
5972
children: [
60-
Text(
61-
DateFormat.yMd(Localizations.localeOf(context).languageCode)
62-
.format(currentImage.date),
63-
style: Theme.of(context).textTheme.headline5,
64-
),
65-
Expanded(
66-
child: Image.network(currentImage.url!),
67-
),
68-
Padding(
69-
padding: const EdgeInsets.symmetric(vertical: 8),
70-
child: Text(currentImage.description),
71-
),
72-
Row(
73-
mainAxisAlignment: MainAxisAlignment.center,
74-
children: [
75-
IconButton(
76-
icon: const Icon(Icons.delete),
77-
onPressed: () {
78-
Provider.of<GalleryProvider>(context, listen: false)
79-
.deleteImage(currentImage);
80-
Navigator.of(context).pop();
81-
}),
82-
if (!(Platform.isLinux || Platform.isMacOS))
83-
IconButton(
84-
icon: const Icon(Icons.edit),
85-
onPressed: () {
86-
Navigator.pushNamed(
87-
context,
88-
FormScreen.routeName,
89-
arguments: FormScreenArguments(
90-
AppLocalizations.of(context).edit,
91-
ImageForm(currentImage),
92-
hasListView: true,
93-
),
94-
);
95-
}),
96-
],
97-
)
73+
IconButton(
74+
icon: const Icon(Icons.delete),
75+
onPressed: () {
76+
Provider.of<GalleryProvider>(context, listen: false)
77+
.deleteImage(currentImage);
78+
Navigator.of(context).pop();
79+
}),
80+
if (!isDesktop)
81+
IconButton(
82+
icon: const Icon(Icons.edit),
83+
onPressed: () {
84+
Navigator.pushNamed(
85+
context,
86+
FormScreen.routeName,
87+
arguments: FormScreenArguments(
88+
AppLocalizations.of(context).edit,
89+
ImageForm(currentImage),
90+
hasListView: true,
91+
),
92+
);
93+
},
94+
),
9895
],
99-
),
100-
),
96+
)
97+
],
10198
),
102-
context: context,
103-
);
104-
},
105-
child: FadeInImage(
106-
key: Key('image-${currentImage.id}'),
107-
placeholder: const AssetImage('assets/images/placeholder.png'),
108-
image: NetworkImage(currentImage.url!),
109-
fit: BoxFit.cover,
110-
),
111-
);
112-
}),
99+
),
100+
context: context,
101+
);
102+
},
103+
child: FadeInImage(
104+
key: Key('image-${currentImage.id}'),
105+
placeholder: const AssetImage('assets/images/placeholder.png'),
106+
image: NetworkImage(currentImage.url!),
107+
fit: BoxFit.cover,
108+
),
109+
);
110+
},
111+
),
113112
),
114113
);
115114
}

lib/widgets/nutrition/widgets.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
import 'dart:io';
20-
2119
import 'package:flutter/material.dart';
2220
import 'package:flutter/services.dart';
2321
import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';
2422
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
2523
import 'package:flutter_typeahead/flutter_typeahead.dart';
2624
import 'package:provider/provider.dart';
2725
import 'package:wger/helpers/consts.dart';
26+
import 'package:wger/helpers/platform.dart';
2827
import 'package:wger/helpers/ui.dart';
2928
import 'package:wger/providers/nutrition.dart';
3029
import 'package:wger/widgets/core/core.dart';
@@ -82,9 +81,7 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
8281
decoration: InputDecoration(
8382
prefixIcon: const Icon(Icons.search),
8483
labelText: AppLocalizations.of(context).searchIngredient,
85-
suffixIcon: (widget.showScanner || Platform.isLinux || Platform.isMacOS)
86-
? scanButton()
87-
: null,
84+
suffixIcon: (widget.showScanner && !isDesktop) ? scanButton() : null,
8885
),
8986
),
9087
suggestionsCallback: (pattern) async {

pubspec.lock

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -555,18 +555,18 @@ packages:
555555
dependency: "direct main"
556556
description:
557557
name: image_picker
558-
sha256: cb25f04595a88450970dbe727243ba8cd21b6f7e0d7d1fc5b789fc6f52e95494
558+
sha256: f202f5d730eb8219e35e80c4461fb3a779940ad30ce8fde1586df756e3af25e6
559559
url: "https://pub.dev"
560560
source: hosted
561-
version: "0.8.7+1"
561+
version: "0.8.7+3"
562562
image_picker_android:
563563
dependency: transitive
564564
description:
565565
name: image_picker_android
566-
sha256: dfb5b0f28b8786fcc662b7ed42bfb4b82a6cbbd74da1958384b10d40bdf212a7
566+
sha256: "1ea6870350f56af8dab716459bd9d5dc76947e29e07a2ba1d0c172eaaf4f269c"
567567
url: "https://pub.dev"
568568
source: hosted
569-
version: "0.8.6+6"
569+
version: "0.8.6+7"
570570
image_picker_for_web:
571571
dependency: transitive
572572
description:
@@ -760,10 +760,10 @@ packages:
760760
dependency: "direct main"
761761
description:
762762
name: package_info_plus
763-
sha256: "8df5ab0a481d7dc20c0e63809e90a588e496d276ba53358afc4c4443d0a00697"
763+
sha256: cbff87676c352d97116af6dbea05aa28c4d65eb0f6d5677a520c11a69ca9a24d
764764
url: "https://pub.dev"
765765
source: hosted
766-
version: "3.0.3"
766+
version: "3.1.0"
767767
package_info_plus_platform_interface:
768768
dependency: transitive
769769
description:
@@ -904,10 +904,10 @@ packages:
904904
dependency: "direct main"
905905
description:
906906
name: rive
907-
sha256: "763b4915b5245428f1188d38c2ff8c26da83ca194d345daa319ca32d69ed670f"
907+
sha256: f7f365ee0e6cf0af99fb239bc3424370ca6ee2b9ad6fc879b1a79ba5e3b40770
908908
url: "https://pub.dev"
909909
source: hosted
910-
version: "0.10.3"
910+
version: "0.10.4"
911911
rive_common:
912912
dependency: transitive
913913
description:
@@ -928,18 +928,18 @@ packages:
928928
dependency: transitive
929929
description:
930930
name: shared_preferences_android
931-
sha256: "8304d8a1f7d21a429f91dee552792249362b68a331ac5c3c1caf370f658873f6"
931+
sha256: "7fa90471a6875d26ad78c7e4a675874b2043874586891128dc5899662c97db46"
932932
url: "https://pub.dev"
933933
source: hosted
934-
version: "2.1.0"
934+
version: "2.1.2"
935935
shared_preferences_foundation:
936936
dependency: transitive
937937
description:
938938
name: shared_preferences_foundation
939-
sha256: cf2a42fb20148502022861f71698db12d937c7459345a1bdaa88fc91a91b3603
939+
sha256: "0c1c16c56c9708aa9c361541a6f0e5cc6fc12a3232d866a687a7b7db30032b07"
940940
url: "https://pub.dev"
941941
source: hosted
942-
version: "2.2.0"
942+
version: "2.2.1"
943943
shared_preferences_linux:
944944
dependency: transitive
945945
description:
@@ -1125,10 +1125,10 @@ packages:
11251125
dependency: transitive
11261126
description:
11271127
name: url_launcher_android
1128-
sha256: dd729390aa936bf1bdf5cd1bc7468ff340263f80a2c4f569416507667de8e3c8
1128+
sha256: a52628068d282d01a07cd86e6ba99e497aa45ce8c91159015b2416907d78e411
11291129
url: "https://pub.dev"
11301130
source: hosted
1131-
version: "6.0.26"
1131+
version: "6.0.27"
11321132
url_launcher_ios:
11331133
dependency: transitive
11341134
description:
@@ -1149,10 +1149,10 @@ packages:
11491149
dependency: transitive
11501150
description:
11511151
name: url_launcher_macos
1152-
sha256: "0ef2b4f97942a16523e51256b799e9aa1843da6c60c55eefbfa9dbc2dcb8331a"
1152+
sha256: "91ee3e75ea9dadf38036200c5d3743518f4a5eb77a8d13fda1ee5764373f185e"
11531153
url: "https://pub.dev"
11541154
source: hosted
1155-
version: "3.0.4"
1155+
version: "3.0.5"
11561156
url_launcher_platform_interface:
11571157
dependency: transitive
11581158
description:
@@ -1301,10 +1301,10 @@ packages:
13011301
dependency: transitive
13021302
description:
13031303
name: web_socket_channel
1304-
sha256: ca49c0bc209c687b887f30527fb6a9d80040b072cc2990f34b9bec3e7663101b
1304+
sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b
13051305
url: "https://pub.dev"
13061306
source: hosted
1307-
version: "2.3.0"
1307+
version: "2.4.0"
13081308
webdriver:
13091309
dependency: transitive
13101310
description:

0 commit comments

Comments
 (0)