diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fc57b2b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +wien_talks/wien_talks_flutter/pubspec.lock diff --git a/wien_talks/wien_talks_flutter/lib/create_event_screen.dart b/wien_talks/wien_talks_flutter/lib/create_event_screen.dart index 00c755a..bc50467 100644 --- a/wien_talks/wien_talks_flutter/lib/create_event_screen.dart +++ b/wien_talks/wien_talks_flutter/lib/create_event_screen.dart @@ -1,5 +1,6 @@ import 'package:flutter/cupertino.dart'; import 'package:wien_talks_flutter/get_location_widget.dart'; +import 'package:wien_talks_flutter/news_input_form.dart'; import 'package:wien_talks_flutter/widgets/screen_widget.dart'; class CreateEventScreen extends StatelessWidget { @@ -12,6 +13,7 @@ class CreateEventScreen extends StatelessWidget { children: [ Text("hello"), GetLocationWidget(), + NewsInputForm(onSubmit: (newsEventModel) {}), ], )); } diff --git a/wien_talks/wien_talks_flutter/lib/get_location_widget.dart b/wien_talks/wien_talks_flutter/lib/get_location_widget.dart index f0c0d0d..4fad495 100644 --- a/wien_talks/wien_talks_flutter/lib/get_location_widget.dart +++ b/wien_talks/wien_talks_flutter/lib/get_location_widget.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:location/location.dart'; import 'package:wien_talks_flutter/location_mgr.dart'; class GetLocationWidget extends StatelessWidget { @@ -6,27 +7,32 @@ class GetLocationWidget extends StatelessWidget { @override Widget build(BuildContext context) { - return FutureBuilder( - future: LocationMgr().startup(), - builder: (BuildContext context, AsyncSnapshot snapshot) { - switch (snapshot.connectionState) { - case ConnectionState.waiting: - return CircularProgressIndicator(); - case ConnectionState.done: - { - if (snapshot.hasData) { - // Error occured - return Text(snapshot.data.toString()); - } else { - return Text("No data -> OK"); - } + return Column( + children: [ + FutureBuilder( + future: LocationMgr().startup(), + builder: (BuildContext context, AsyncSnapshot snapshot) { + switch (snapshot.connectionState) { + case ConnectionState.waiting: + return CircularProgressIndicator(); + case ConnectionState.done: + { + if (snapshot.hasData) { + // Error occured + return Text(snapshot.data.toString()); + } else { + return Text("No data -> OK"); + } + } + default: + if (snapshot.hasError) { + return Text('Error: ${snapshot.error}'); + } + return Text("OK"); } - default: - if (snapshot.hasError) { - return Text('Error: ${snapshot.error}'); - } - return Text("OK"); - } - }); + }), + StreamBuilder(stream: LocationMgr().stream, builder: (BuildContext context, AsyncSnapshot snapshot) => Text(snapshot.data.toString())), + ], + ); } } diff --git a/wien_talks/wien_talks_flutter/lib/location_mgr.dart b/wien_talks/wien_talks_flutter/lib/location_mgr.dart index c2f7509..1ab24b9 100644 --- a/wien_talks/wien_talks_flutter/lib/location_mgr.dart +++ b/wien_talks/wien_talks_flutter/lib/location_mgr.dart @@ -1,4 +1,7 @@ +import 'dart:async'; + import 'package:location/location.dart'; +import 'package:rxdart/rxdart.dart'; class LocationMgr { Location location = Location(); @@ -7,10 +10,14 @@ class LocationMgr { PermissionStatus permissionGranted = PermissionStatus.denied; - LocationData? locationData; + LocationData? _lastLocationData; static LocationMgr? _instance; + final Subject _subject = PublishSubject(); + + StreamSubscription? _subscription; + factory LocationMgr() { _instance ??= LocationMgr._(); return _instance!; @@ -34,6 +41,19 @@ class LocationMgr { return "No permissions granted"; } } + _subscription = location.onLocationChanged.listen((LocationData currentLocation) { + _lastLocationData = currentLocation; + _subject.add(currentLocation); + }); return null; } + + void shutdown() { + _subscription?.cancel(); + _subscription = null; + } + + Stream get stream => _subject.stream; + + LocationData? get lastLocation => _lastLocationData; } diff --git a/wien_talks/wien_talks_flutter/lib/models/news_event_model.dart b/wien_talks/wien_talks_flutter/lib/models/news_event_model.dart new file mode 100644 index 0000000..d1fce39 --- /dev/null +++ b/wien_talks/wien_talks_flutter/lib/models/news_event_model.dart @@ -0,0 +1,34 @@ +class NewsEventModel { + final String content; + + final DateTime timestamp; + + final double latitude; + + final double longitude; + + NewsEventModel({ + required this.content, + required this.timestamp, + required this.latitude, + required this.longitude, + }); + +// Convert NewsData to a Map + Map toJson() { + return { + 'content': content, + 'timestamp': timestamp.toIso8601String(), + }; + } + +// Create NewsData from a Map + factory NewsEventModel.fromJson(Map json) { + return NewsEventModel( + content: json['content'] as String, + timestamp: DateTime.parse(json['timestamp'] as String), + latitude: json['latitude'] as double, + longitude: json['longitude'] as double, + ); + } +} diff --git a/wien_talks/wien_talks_flutter/lib/news_input_form.dart b/wien_talks/wien_talks_flutter/lib/news_input_form.dart new file mode 100644 index 0000000..0a99302 --- /dev/null +++ b/wien_talks/wien_talks_flutter/lib/news_input_form.dart @@ -0,0 +1,71 @@ +import 'package:flutter/material.dart'; +import 'package:wien_talks_flutter/models/news_event_model.dart'; + +class NewsInputForm extends StatefulWidget { + final Function(NewsEventModel) onSubmit; + + const NewsInputForm({Key? key, required this.onSubmit}) : super(key: key); + + @override + _NewsInputFormState createState() => _NewsInputFormState(); +} + +class _NewsInputFormState extends State { + final _formKey = GlobalKey(); + final TextEditingController _newsController = TextEditingController(); + + @override + void dispose() { + _newsController.dispose(); + super.dispose(); + } + + void _submitForm() { + if (_formKey.currentState!.validate()) { + final newsData = NewsEventModel( + content: _newsController.text.trim(), + timestamp: DateTime.now(), + latitude: 0.0, + longitude: 0.0, + ); + widget.onSubmit(newsData); + _newsController.clear(); + } + } + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.all(16.0), + child: Form( + key: _formKey, + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + mainAxisSize: MainAxisSize.min, + children: [ + TextFormField( + controller: _newsController, + maxLines: 4, + decoration: const InputDecoration( + labelText: 'News', + hintText: 'Enter your news here...', + border: OutlineInputBorder(), + ), + validator: (value) { + if (value == null || value.trim().isEmpty) { + return 'Please enter some text'; + } + return null; + }, + ), + const SizedBox(height: 16.0), + ElevatedButton( + onPressed: _submitForm, + child: const Text('Submit News'), + ), + ], + ), + ), + ); + } +} diff --git a/wien_talks/wien_talks_flutter/pubspec.lock b/wien_talks/wien_talks_flutter/pubspec.lock deleted file mode 100644 index 0558773..0000000 --- a/wien_talks/wien_talks_flutter/pubspec.lock +++ /dev/null @@ -1,449 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - args: - dependency: transitive - description: - name: args - sha256: d0481093c50b1da8910eb0bb301626d4d8eb7284aa739614d2b394ee09e3ea04 - url: "https://pub.dev" - source: hosted - version: "2.7.0" - async: - dependency: transitive - description: - name: async - sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb" - url: "https://pub.dev" - source: hosted - version: "2.13.0" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea" - url: "https://pub.dev" - source: hosted - version: "2.1.2" - characters: - dependency: transitive - description: - name: characters - sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803 - url: "https://pub.dev" - source: hosted - version: "1.4.0" - clock: - dependency: transitive - description: - name: clock - sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b - url: "https://pub.dev" - source: hosted - version: "1.1.2" - collection: - dependency: transitive - description: - name: collection - sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76" - url: "https://pub.dev" - source: hosted - version: "1.19.1" - connectivity_plus: - dependency: transitive - description: - name: connectivity_plus - sha256: b5e72753cf63becce2c61fd04dfe0f1c430cc5278b53a1342dc5ad839eab29ec - url: "https://pub.dev" - source: hosted - version: "6.1.5" - connectivity_plus_platform_interface: - dependency: transitive - description: - name: connectivity_plus_platform_interface - sha256: "42657c1715d48b167930d5f34d00222ac100475f73d10162ddf43e714932f204" - url: "https://pub.dev" - source: hosted - version: "2.0.1" - crypto: - dependency: transitive - description: - name: crypto - sha256: "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855" - url: "https://pub.dev" - source: hosted - version: "3.0.6" - cupertino_icons: - dependency: "direct main" - description: - name: cupertino_icons - sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6 - url: "https://pub.dev" - source: hosted - version: "1.0.8" - dbus: - dependency: transitive - description: - name: dbus - sha256: "79e0c23480ff85dc68de79e2cd6334add97e48f7f4865d17686dd6ea81a47e8c" - url: "https://pub.dev" - source: hosted - version: "0.7.11" - fake_async: - dependency: transitive - description: - name: fake_async - sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44" - url: "https://pub.dev" - source: hosted - version: "1.3.3" - ffi: - dependency: transitive - description: - name: ffi - sha256: "289279317b4b16eb2bb7e271abccd4bf84ec9bdcbe999e278a94b804f5630418" - url: "https://pub.dev" - source: hosted - version: "2.1.4" - fixnum: - dependency: transitive - description: - name: fixnum - sha256: b6dc7065e46c974bc7c5f143080a6764ec7a4be6da1285ececdc37be96de53be - url: "https://pub.dev" - source: hosted - version: "1.1.1" - flutter: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" - flutter_lints: - dependency: "direct dev" - description: - name: flutter_lints - sha256: "3105dc8492f6183fb076ccf1f351ac3d60564bff92e20bfc4af9cc1651f4e7e1" - url: "https://pub.dev" - source: hosted - version: "6.0.0" - flutter_test: - dependency: "direct dev" - description: flutter - source: sdk - version: "0.0.0" - flutter_web_plugins: - dependency: transitive - description: flutter - source: sdk - version: "0.0.0" - go_router: - dependency: "direct main" - description: - name: go_router - sha256: "8b1f37dfaf6e958c6b872322db06f946509433bec3de753c3491a42ae9ec2b48" - url: "https://pub.dev" - source: hosted - version: "16.1.0" - http: - dependency: transitive - description: - name: http - sha256: bb2ce4590bc2667c96f318d68cac1b5a7987ec819351d32b1c987239a815e007 - url: "https://pub.dev" - source: hosted - version: "1.5.0" - http_parser: - dependency: transitive - description: - name: http_parser - sha256: "178d74305e7866013777bab2c3d8726205dc5a4dd935297175b19a23a2e66571" - url: "https://pub.dev" - source: hosted - version: "4.1.2" - leak_tracker: - dependency: transitive - description: - name: leak_tracker - sha256: "6bb818ecbdffe216e81182c2f0714a2e62b593f4a4f13098713ff1685dfb6ab0" - url: "https://pub.dev" - source: hosted - version: "10.0.9" - leak_tracker_flutter_testing: - dependency: transitive - description: - name: leak_tracker_flutter_testing - sha256: f8b613e7e6a13ec79cfdc0e97638fddb3ab848452eff057653abd3edba760573 - url: "https://pub.dev" - source: hosted - version: "3.0.9" - leak_tracker_testing: - dependency: transitive - description: - name: leak_tracker_testing - sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" - url: "https://pub.dev" - source: hosted - version: "3.0.1" - lints: - dependency: transitive - description: - name: lints - sha256: a5e2b223cb7c9c8efdc663ef484fdd95bb243bff242ef5b13e26883547fce9a0 - url: "https://pub.dev" - source: hosted - version: "6.0.0" - location: - dependency: "direct main" - description: - name: location - sha256: b080053c181c7d152c43dd576eec6436c40e25f326933051c330da563ddd5333 - url: "https://pub.dev" - source: hosted - version: "8.0.1" - location_platform_interface: - dependency: transitive - description: - name: location_platform_interface - sha256: ca8700bb3f6b1e8b2afbd86bd78b2280d116c613ca7bfa1d4d7b64eba357d749 - url: "https://pub.dev" - source: hosted - version: "6.0.1" - location_web: - dependency: transitive - description: - name: location_web - sha256: b8e3add5efe0d65c5e692b7a135d80a4015c580d3ea646fa71973e97668dd868 - url: "https://pub.dev" - source: hosted - version: "6.0.1" - logging: - dependency: transitive - description: - name: logging - sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61 - url: "https://pub.dev" - source: hosted - version: "1.3.0" - matcher: - dependency: transitive - description: - name: matcher - sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2 - url: "https://pub.dev" - source: hosted - version: "0.12.17" - material_color_utilities: - dependency: transitive - description: - name: material_color_utilities - sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec - url: "https://pub.dev" - source: hosted - version: "0.11.1" - meta: - dependency: transitive - description: - name: meta - sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c - url: "https://pub.dev" - source: hosted - version: "1.16.0" - nm: - dependency: transitive - description: - name: nm - sha256: "2c9aae4127bdc8993206464fcc063611e0e36e72018696cd9631023a31b24254" - url: "https://pub.dev" - source: hosted - version: "0.5.0" - path: - dependency: transitive - description: - name: path - sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5" - url: "https://pub.dev" - source: hosted - version: "1.9.1" - petitparser: - dependency: transitive - description: - name: petitparser - sha256: "07c8f0b1913bcde1ff0d26e57ace2f3012ccbf2b204e070290dad3bb22797646" - url: "https://pub.dev" - source: hosted - version: "6.1.0" - plugin_platform_interface: - dependency: transitive - description: - name: plugin_platform_interface - sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02" - url: "https://pub.dev" - source: hosted - version: "2.1.8" - serverpod_client: - dependency: transitive - description: - name: serverpod_client - sha256: "04cb6d36730c8c24c067cde6e41551ad2dd7ae3725bbaa2756e82d2f5b345f54" - url: "https://pub.dev" - source: hosted - version: "2.9.1" - serverpod_flutter: - dependency: "direct main" - description: - name: serverpod_flutter - sha256: "1d9c2cb511581a7fdc1fc81ac5475ef75c0cf0a1c9181308e956db4818759bb7" - url: "https://pub.dev" - source: hosted - version: "2.9.1" - serverpod_serialization: - dependency: transitive - description: - name: serverpod_serialization - sha256: c301a5e45610c062e51e1ba580f51f3257c3404ce2dd2f7e216dccbd93869502 - url: "https://pub.dev" - source: hosted - version: "2.9.1" - sky_engine: - dependency: transitive - description: flutter - source: sdk - version: "0.0.0" - source_span: - dependency: transitive - description: - name: source_span - sha256: "254ee5351d6cb365c859e20ee823c3bb479bf4a293c22d17a9f1bf144ce86f7c" - url: "https://pub.dev" - source: hosted - version: "1.10.1" - sprintf: - dependency: transitive - description: - name: sprintf - sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23" - url: "https://pub.dev" - source: hosted - version: "7.0.0" - stack_trace: - dependency: transitive - description: - name: stack_trace - sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1" - url: "https://pub.dev" - source: hosted - version: "1.12.1" - stream_channel: - dependency: transitive - description: - name: stream_channel - sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d" - url: "https://pub.dev" - source: hosted - version: "2.1.4" - string_scanner: - dependency: transitive - description: - name: string_scanner - sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43" - url: "https://pub.dev" - source: hosted - version: "1.4.1" - term_glyph: - dependency: transitive - description: - name: term_glyph - sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e" - url: "https://pub.dev" - source: hosted - version: "1.2.2" - test_api: - dependency: transitive - description: - name: test_api - sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd - url: "https://pub.dev" - source: hosted - version: "0.7.4" - typed_data: - dependency: transitive - description: - name: typed_data - sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006 - url: "https://pub.dev" - source: hosted - version: "1.4.0" - uuid: - dependency: transitive - description: - name: uuid - sha256: a5be9ef6618a7ac1e964353ef476418026db906c4facdedaa299b7a2e71690ff - url: "https://pub.dev" - source: hosted - version: "4.5.1" - vector_math: - dependency: transitive - description: - name: vector_math - sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" - url: "https://pub.dev" - source: hosted - version: "2.1.4" - vm_service: - dependency: transitive - description: - name: vm_service - sha256: ddfa8d30d89985b96407efce8acbdd124701f96741f2d981ca860662f1c0dc02 - url: "https://pub.dev" - source: hosted - version: "15.0.0" - web: - dependency: transitive - description: - name: web - sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a" - url: "https://pub.dev" - source: hosted - version: "1.1.1" - web_socket: - dependency: transitive - description: - name: web_socket - sha256: "34d64019aa8e36bf9842ac014bb5d2f5586ca73df5e4d9bf5c936975cae6982c" - url: "https://pub.dev" - source: hosted - version: "1.0.1" - web_socket_channel: - dependency: transitive - description: - name: web_socket_channel - sha256: d645757fb0f4773d602444000a8131ff5d48c9e47adfe9772652dd1a4f2d45c8 - url: "https://pub.dev" - source: hosted - version: "3.0.3" - wien_talks_client: - dependency: "direct main" - description: - path: "../wien_talks_client" - relative: true - source: path - version: "0.0.0" - xml: - dependency: transitive - description: - name: xml - sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226 - url: "https://pub.dev" - source: hosted - version: "6.5.0" - yaml: - dependency: transitive - description: - name: yaml - sha256: b9da305ac7c39faa3f030eccd175340f968459dae4af175130b3fc47e40d76ce - url: "https://pub.dev" - source: hosted - version: "3.1.3" -sdks: - dart: ">=3.8.0 <4.0.0" - flutter: ">=3.27.0" diff --git a/wien_talks/wien_talks_flutter/pubspec.yaml b/wien_talks/wien_talks_flutter/pubspec.yaml index 5490c5a..f0706d2 100644 --- a/wien_talks/wien_talks_flutter/pubspec.yaml +++ b/wien_talks/wien_talks_flutter/pubspec.yaml @@ -29,6 +29,8 @@ dependencies: location: ^8.0.1 + rxdart: ^0.28.0 + serverpod_flutter: 2.9.1 wien_talks_client: @@ -36,7 +38,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^1.0.5 + cupertino_icons: ^1.0.8 dev_dependencies: flutter_lints: '>=3.0.0 <7.0.0'