Skip to content

Commit 1c5b39a

Browse files
committed
add a product info dialog to the overview
1 parent 7814d0a commit 1c5b39a

File tree

10 files changed

+163
-10
lines changed

10 files changed

+163
-10
lines changed

lib/overview.dart

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
import 'package:flutter/material.dart';
22
import 'package:get_it/get_it.dart';
33
import 'package:ka_client/product.dart';
4+
import 'package:ka_client/style_components/product_info_dialog.dart';
45

56
import 'api_connection.dart';
67

7-
class Overview extends StatefulWidget {
8-
const Overview({super.key});
8+
class Overview extends StatelessWidget {
9+
final Future<List<Product>> products = GetIt.I<APIConnection>().products;
910

10-
@override
11-
State<Overview> createState() => _OverviewState();
12-
}
13-
14-
class _OverviewState extends State<Overview> {
15-
Future<List<Product>> products = GetIt.I<APIConnection>().products;
11+
Overview({super.key});
1612

1713
@override
1814
Widget build(BuildContext context) {
@@ -27,6 +23,14 @@ class _OverviewState extends State<Overview> {
2723
title: Text(products[index].title),
2824
subtitle: Text(products[index].location),
2925
trailing: Text(products[index].price.toString()),
26+
onTap: () {
27+
showDialog(
28+
context: context,
29+
builder: (context) {
30+
return ProductInfoDialog(product: products[index]);
31+
},
32+
);
33+
}
3034
);
3135
},
3236
);

lib/style_components/app_scaffold.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AppScaffold extends StatefulWidget {
1414

1515
class _AppScaffoldState extends State<AppScaffold> {
1616
final _pages = {
17-
"Overview": const Overview(),
17+
"Overview": Overview(),
1818
"Price Chart": PriceChartPage(),
1919
};
2020

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:url_launcher/url_launcher.dart';
3+
4+
import '../product.dart';
5+
6+
class ProductInfoDialog extends StatelessWidget {
7+
final Product product;
8+
9+
Future<void> _launchUrl(url) async {
10+
if (!await launchUrl(url)) {
11+
throw Exception('Could not launch $url');
12+
}
13+
}
14+
15+
const ProductInfoDialog({super.key, required this.product});
16+
17+
@override
18+
Widget build(BuildContext context) {
19+
return SimpleDialog(
20+
title: Text(product.title),
21+
shape: RoundedRectangleBorder(
22+
borderRadius: BorderRadius.circular(20.0),
23+
),
24+
children: [
25+
ListTile(
26+
leading: const Icon(Icons.attach_money),
27+
title: const Text('Price'),
28+
subtitle: Text(product.price.toString()),
29+
),
30+
ListTile(
31+
leading: const Icon(Icons.location_on),
32+
title: const Text('Location'),
33+
subtitle: Text(product.location + (product.vb ? ' VB' : '')),
34+
),
35+
ListTile(
36+
leading: const Icon(Icons.local_shipping),
37+
title: const Text('Shipping'),
38+
subtitle: Text(product.shipping ? 'Yes' : 'No'),
39+
),
40+
ListTile(
41+
leading: const Icon(Icons.open_in_browser),
42+
title: const Text('Open in browser'),
43+
onTap: () {
44+
// Open the product in the browser
45+
_launchUrl(Uri.parse("https://www.kleinanzeigen.de/s-anzeige/${product.id.toString()}"));
46+
},
47+
)
48+
],
49+
);
50+
}
51+
}

linux/flutter/generated_plugin_registrant.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
#include "generated_plugin_registrant.h"
88

9+
#include <url_launcher_linux/url_launcher_plugin.h>
910

1011
void fl_register_plugins(FlPluginRegistry* registry) {
12+
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
13+
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
14+
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
1115
}

linux/flutter/generated_plugins.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44

55
list(APPEND FLUTTER_PLUGIN_LIST
6+
url_launcher_linux
67
)
78

89
list(APPEND FLUTTER_FFI_PLUGIN_LIST

macos/Flutter/GeneratedPluginRegistrant.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import FlutterMacOS
66
import Foundation
77

8+
import url_launcher_macos
89

910
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
11+
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
1012
}

pubspec.lock

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ packages:
9191
description: flutter
9292
source: sdk
9393
version: "0.0.0"
94+
flutter_web_plugins:
95+
dependency: transitive
96+
description: flutter
97+
source: sdk
98+
version: "0.0.0"
9499
get_it:
95100
dependency: "direct main"
96101
description:
@@ -179,6 +184,14 @@ packages:
179184
url: "https://pub.dev"
180185
source: hosted
181186
version: "1.9.0"
187+
plugin_platform_interface:
188+
dependency: transitive
189+
description:
190+
name: plugin_platform_interface
191+
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
192+
url: "https://pub.dev"
193+
source: hosted
194+
version: "2.1.8"
182195
sky_engine:
183196
dependency: transitive
184197
description: flutter
@@ -240,6 +253,70 @@ packages:
240253
url: "https://pub.dev"
241254
source: hosted
242255
version: "1.3.2"
256+
url_launcher:
257+
dependency: "direct main"
258+
description:
259+
name: url_launcher
260+
sha256: c512655380d241a337521703af62d2c122bf7b77a46ff7dd750092aa9433499c
261+
url: "https://pub.dev"
262+
source: hosted
263+
version: "6.2.4"
264+
url_launcher_android:
265+
dependency: transitive
266+
description:
267+
name: url_launcher_android
268+
sha256: d4ed0711849dd8e33eb2dd69c25db0d0d3fdc37e0a62e629fe32f57a22db2745
269+
url: "https://pub.dev"
270+
source: hosted
271+
version: "6.3.0"
272+
url_launcher_ios:
273+
dependency: transitive
274+
description:
275+
name: url_launcher_ios
276+
sha256: "75bb6fe3f60070407704282a2d295630cab232991eb52542b18347a8a941df03"
277+
url: "https://pub.dev"
278+
source: hosted
279+
version: "6.2.4"
280+
url_launcher_linux:
281+
dependency: transitive
282+
description:
283+
name: url_launcher_linux
284+
sha256: ab360eb661f8879369acac07b6bb3ff09d9471155357da8443fd5d3cf7363811
285+
url: "https://pub.dev"
286+
source: hosted
287+
version: "3.1.1"
288+
url_launcher_macos:
289+
dependency: transitive
290+
description:
291+
name: url_launcher_macos
292+
sha256: b7244901ea3cf489c5335bdacda07264a6e960b1c1b1a9f91e4bc371d9e68234
293+
url: "https://pub.dev"
294+
source: hosted
295+
version: "3.1.0"
296+
url_launcher_platform_interface:
297+
dependency: transitive
298+
description:
299+
name: url_launcher_platform_interface
300+
sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029"
301+
url: "https://pub.dev"
302+
source: hosted
303+
version: "2.3.2"
304+
url_launcher_web:
305+
dependency: transitive
306+
description:
307+
name: url_launcher_web
308+
sha256: "3692a459204a33e04bc94f5fb91158faf4f2c8903281ddd82915adecdb1a901d"
309+
url: "https://pub.dev"
310+
source: hosted
311+
version: "2.3.0"
312+
url_launcher_windows:
313+
dependency: transitive
314+
description:
315+
name: url_launcher_windows
316+
sha256: ecf9725510600aa2bb6d7ddabe16357691b6d2805f66216a97d1b881e21beff7
317+
url: "https://pub.dev"
318+
source: hosted
319+
version: "3.1.1"
243320
vector_math:
244321
dependency: transitive
245322
description:
@@ -256,5 +333,14 @@ packages:
256333
url: "https://pub.dev"
257334
source: hosted
258335
version: "13.0.0"
336+
web:
337+
dependency: transitive
338+
description:
339+
name: web
340+
sha256: "1d9158c616048c38f712a6646e317a3426da10e884447626167240d45209cbad"
341+
url: "https://pub.dev"
342+
source: hosted
343+
version: "0.5.0"
259344
sdks:
260-
dart: ">=3.2.0-0 <4.0.0"
345+
dart: ">=3.3.0 <4.0.0"
346+
flutter: ">=3.19.0"

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ dependencies:
3838
http:
3939
fl_chart:
4040
get_it: ^7.6.7
41+
url_launcher: ^6.2.4
4142

4243
dev_dependencies:
4344
flutter_test:

windows/flutter/generated_plugin_registrant.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
#include "generated_plugin_registrant.h"
88

9+
#include <url_launcher_windows/url_launcher_windows.h>
910

1011
void RegisterPlugins(flutter::PluginRegistry* registry) {
12+
UrlLauncherWindowsRegisterWithRegistrar(
13+
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
1114
}

windows/flutter/generated_plugins.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44

55
list(APPEND FLUTTER_PLUGIN_LIST
6+
url_launcher_windows
67
)
78

89
list(APPEND FLUTTER_FFI_PLUGIN_LIST

0 commit comments

Comments
 (0)