From ebe61c1674ab4f101c00dd70a63c6ba82ac7d1e2 Mon Sep 17 00:00:00 2001 From: Sven Carstensen Date: Sun, 28 Jan 2024 17:35:12 +0100 Subject: [PATCH] Erweiterungen --- lib/content_views/assigned_jobs_page.dart | 134 --------------- lib/content_views/main_page.dart | 77 ++++----- lib/main.dart | 8 +- lib/popups/accept_job_popup.dart | 130 --------------- lib/popups/accept_jobs_popup.dart | 195 ++++++++++++++++++++++ pubspec.lock | 56 +++++++ pubspec.yaml | 2 + 7 files changed, 299 insertions(+), 303 deletions(-) delete mode 100644 lib/content_views/assigned_jobs_page.dart delete mode 100644 lib/popups/accept_job_popup.dart create mode 100644 lib/popups/accept_jobs_popup.dart diff --git a/lib/content_views/assigned_jobs_page.dart b/lib/content_views/assigned_jobs_page.dart deleted file mode 100644 index 85cb40c..0000000 --- a/lib/content_views/assigned_jobs_page.dart +++ /dev/null @@ -1,134 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:isar/isar.dart'; -import 'package:stadtbote/content_views/utils/content_view_widget.dart'; -import 'package:stadtbote/content_views/utils/header_info.dart'; -import 'package:intl/intl.dart'; -import 'package:stadtbote/popups/accept_job_popup.dart'; - -import '../main.dart'; -import '../model/job.dart'; -import '../tools/util.dart'; - -class AssignedJobsPage extends ContentViewWidget { - const AssignedJobsPage({super.key}); - - @override - State createState() => _AssignedJobsPageState(); - - @override - Future getHeaderInfo(BuildContext context) async { - return HeaderInfo( - titleWidget: const Text( - 'Zugewiesene Aufträge', - style: TextStyle( - color: Colors.white, - fontSize: 24.0, - ), - ), - rightButtonEnabled: false, - rightButtonVisible: false, - rightButtonImage: null, - rightButtonOnPressed: () async { - //BroadcastReceiver().publish(Constants.messageTopicPushContentView, arguments: EmployeeEditProfileWidget()); - }); - } -} - -class _AssignedJobsPageState extends State { - late List _jobs; - - late bool _initCompleted = false; - - @override - void initState() { - Future.delayed(const Duration(seconds: 0), () async { - _jobs = await MyApp.isarInstance.jobs.filter().stateEqualTo(0).findAll(); - - _initCompleted = true; - - setState(() {}); - }); - - super.initState(); - } - - @override - Widget build(BuildContext context) { - if (!_initCompleted) { - return Util.getWaitWidget(context); - } - - late List jobWidgets = _createjobWidgets(); - - return ListView( - children: jobWidgets - ); - } - - List _createjobWidgets() { - List jobWidgets = []; - - for (var job in _jobs) { - jobWidgets.add( - ListTile( - onTap: () { - _clicked(job); - }, - title: Container( - decoration: BoxDecoration( - color: Colors.white, - border: Border.all(color: Colors.grey, width: 0.5), - borderRadius: const BorderRadius.all(Radius.circular(13)) - ), - padding: const EdgeInsets.all(15.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - DateFormat('dd.MM.yyyy HH:mm').format(DateTime.parse(job.ordertime)).toString(), - textAlign: TextAlign.left, - ), - Text( - job.crFilter != null ? job.crFilter.toString() : "Kein CR-Filter vorhanden", - textAlign: TextAlign.left, - ), - Row( - children: [ - const Icon(Icons.arrow_back, size: 30.0, color: Colors.black), - const SizedBox(width: 10), - Text( - job.vhtId.toString() - ), - ], - ), - Text( - job.id.toString(), - textAlign: TextAlign.left, - ), - Text( - job.tours[0].comp, - textAlign: TextAlign.left, - ), - Text( - job.tours[0].street, - textAlign: TextAlign.left, - ), - Text( - job.tours[0].city, - textAlign: TextAlign.left, - ), - ], - ), - ) - ), - ); - } - - return jobWidgets; - } - - void _clicked(Job job) { - showAcceptJobPopup(context, job); - } -} diff --git a/lib/content_views/main_page.dart b/lib/content_views/main_page.dart index a2b7302..ed61f0d 100644 --- a/lib/content_views/main_page.dart +++ b/lib/content_views/main_page.dart @@ -1,16 +1,14 @@ - import 'package:flutter/material.dart'; import 'package:flutter_broadcast_receiver/flutter_broadcast_receiver.dart'; import 'package:isar/isar.dart'; import 'package:stadtbote/content_views/accepted_jobs_page.dart'; -import 'package:stadtbote/content_views/assigned_jobs_page.dart'; import 'package:stadtbote/content_views/finished_jobs_page.dart'; import 'package:stadtbote/content_views/messages_page.dart'; import 'package:stadtbote/content_views/utils/content_view_widget.dart'; import 'package:stadtbote/content_views/utils/header_info.dart'; import 'package:stadtbote/model/job.dart'; import 'package:stadtbote/model/status.dart'; -import 'package:stadtbote/popups/accept_job_popup.dart'; +import 'package:stadtbote/popups/accept_jobs_popup.dart'; import 'package:stadtbote/popups/infos_popup.dart'; import 'package:stadtbote/tools/messages/job_received_message.dart'; import 'package:stadtbote/tools/messages/session_info_update.dart'; @@ -88,7 +86,7 @@ class _MainPageState extends State { super.initState(); _refreshBadges(); - + _initMessages(); } @@ -105,34 +103,6 @@ class _MainPageState extends State { children: [ ValueListenableBuilder( valueListenable: _assignedJobsValueNotifier, - builder: (context, value, child) { - return badges.Badge( - showBadge: value > 0, - position: badges.BadgePosition.topEnd(top: -12, end: -5), - badgeContent: Text( - value.toString(), - style: const TextStyle( - color: Colors.white, - fontSize: 13.0, - ), - ), - badgeStyle: badges.BadgeStyle( - badgeColor: Colors.red, - padding: const EdgeInsets.all(10), - borderRadius: BorderRadius.circular(4), - borderSide: const BorderSide(color: Colors.white, width: 0), - elevation: 0, - ), - child: getDefaultButton( - 'Zugewiesene Aufträge', - image: Image.asset('assets/zugewiesene_auftraege.png', width: 30, height: 30), - () => {BroadcastReceiver().publish(Constants.messageTopicPushContentView, arguments: const AssignedJobsPage())}) - ); - }, - ), - const SizedBox(height: 20), - ValueListenableBuilder( - valueListenable: _acceptedJobsValueNotifier, builder: (context, value, child) { return badges.Badge( showBadge: value > 0, @@ -152,13 +122,43 @@ class _MainPageState extends State { elevation: 0, ), child: getDefaultButton( - 'Angenommene Aufträge', - image: Image.asset('assets/angenommene_auftraege.png', width: 30, height: 30), - () => {BroadcastReceiver().publish(Constants.messageTopicPushContentView, arguments: const AcceptedJobsPage())}) + 'Zugewiesene Aufträge', + image: Image.asset('assets/zugewiesene_auftraege.png', width: 30, height: 30), + () => {showAcceptJobsPopup(context)}), ); }, ), const SizedBox(height: 20), + ValueListenableBuilder( + valueListenable: _acceptedJobsValueNotifier, + builder: (context, value, child) { + return badges.Badge( + showBadge: value > 0, + position: badges.BadgePosition.topEnd(top: -12, end: -5), + badgeContent: Text( + value.toString(), + style: const TextStyle( + color: Colors.white, + fontSize: 13.0, + ), + ), + badgeStyle: badges.BadgeStyle( + badgeColor: Colors.red, + padding: const EdgeInsets.all(10), + borderRadius: BorderRadius.circular(4), + borderSide: const BorderSide(color: Colors.white, width: 0), + elevation: 0, + ), + child: getDefaultButton( + 'Angenommene Aufträge', + image: Image.asset('assets/angenommene_auftraege.png', width: 30, height: 30), + () => { + BroadcastReceiver() + .publish(Constants.messageTopicPushContentView, arguments: const AcceptedJobsPage()) + })); + }, + ), + const SizedBox(height: 20), getDefaultButton( 'Erledigte Aufträge', image: Image.asset('assets/erledigte_auftraege.png', width: 30, height: 30), @@ -187,8 +187,9 @@ class _MainPageState extends State { child: getDefaultButton( 'Nachrichten', image: Image.asset('assets/nachrichten.png', width: 30, height: 30), - () => {BroadcastReceiver().publish(Constants.messageTopicPushContentView, arguments: const MessagesPage())}) - ); + () => { + BroadcastReceiver().publish(Constants.messageTopicPushContentView, arguments: const MessagesPage()) + })); }, ), const SizedBox(height: 20), @@ -266,6 +267,6 @@ class _MainPageState extends State { } void _showAcceptanceDialog(Job job) { - showAcceptJobPopup(context, job); + showAcceptJobsPopup(context); } } diff --git a/lib/main.dart b/lib/main.dart index 2abddaf..4239174 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -134,7 +134,13 @@ class _MainState extends State
{ key: GlobalKey(), child: WillPopScope( onWillPop: () async { - return false; + if (contentStack.isNotEmpty) { + _popContentView(); + + return false; + } else { + return true; + } }, child: Scaffold( appBar: PreferredSize( diff --git a/lib/popups/accept_job_popup.dart b/lib/popups/accept_job_popup.dart deleted file mode 100644 index d794b39..0000000 --- a/lib/popups/accept_job_popup.dart +++ /dev/null @@ -1,130 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:intl/intl.dart'; -import 'package:kumi_popup_window/kumi_popup_window.dart'; -import 'package:stadtbote/main.dart'; -import 'package:stadtbote/model/job.dart'; -import 'package:stadtbote/tools/util.dart'; - -void showAcceptJobPopup(BuildContext context, Job job) async { - showPopupWindow( - context, - //childSize:Size(240, MediaQuery.of(context).size.width * 0.8), - gravity: KumiPopupGravity.center, - //curve: Curves.elasticOut, - bgColor: Colors.grey.withOpacity(0.5), - clickOutDismiss: true, - clickBackDismiss: true, - customAnimation: false, - customPop: false, - customPage: false, - // targetRenderBox: (btnKey.currentContext.findRenderObject() as RenderBox), - //needSafeDisplay: true, - underStatusBar: false, - underAppBar: false, - //offsetX: -180, - //offsetY: 50, - duration: const Duration(milliseconds: 200), - onShowStart: (pop) {}, - onShowFinish: (pop) {}, - onDismissStart: (pop) {}, - onDismissFinish: (pop) {}, - onClickOut: (pop) {}, - onClickBack: (pop) {}, - childFun: (pop) { - return SizedBox( - key: GlobalKey(), - height: MediaQuery.of(context).size.height * 0.5, - width: MediaQuery.of(context).size.width * 0.8, - child: Container( - height: 100, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - color: Colors.white, - border: Border.all( - color: Colors.grey, - width: 0.5, - ), - ), - child: Padding( - padding: const EdgeInsets.all(12.0), - child: Column( - children: [ - Text(DateFormat('dd.MM.yyyy HH:mm').format(DateTime.parse(job.ordertime)).toString(), textAlign: TextAlign.left), - Text('Auftragsnummer: ${job.id}'), - Text(job.tours[0].comp), - Text(job.tours[0].street), - Text(job.tours[0].city), - const SizedBox(height: 20), - Container( - height: 200, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - color: const Color(0xfffff4e4), - border: Border.all( - color: Colors.grey, - width: 0.5, - ), - ), - child: const SingleChildScrollView( - child: Text('asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd '), - ), - ), - const SizedBox(height: 20), - Row( - children: [ - Expanded( - child: getDefaultButton( - 'Ablehnen', - () => {_sendAnswer()}), - ), - const SizedBox(width: 20), - Expanded( - child: getDefaultButton( - 'Annehmen', - () => {}), - ) - ] - ) - ], - ), - ), - ) - ); - }, - ); -} - -/* -private void SendAnswer(int item) - { - JObject payloadObject; - - var location = App.CurrentLocation; - if (location != null) - payloadObject = new JObject( - new JProperty("reaction", new JObject( - new JProperty("id", _jobViewModel.IdString), - new JProperty("ver", _jobViewModel.Version), - new JProperty("item", item), - new JProperty("track", new JObject( - new JProperty("time", DateTime.Now.ToString("o")), - new JProperty("pos", new JObject( - new JProperty("lat", location.Latitude), - new JProperty("long", location.Longitude), - new JProperty("acc", location.Accuracy)))))))); - else - payloadObject = new JObject( - new JProperty("reaction", new JObject( - new JProperty("id", _jobViewModel.IdString), - new JProperty("ver", _jobViewModel.Version), - new JProperty("item", item), - new JProperty("track", new JObject( - new JProperty("time", DateTime.Now.ToString("o"))))))); - - App.Core.SendJsonMessageAsync("job", payloadObject); - } - */ - -_sendAnswer() { - -} \ No newline at end of file diff --git a/lib/popups/accept_jobs_popup.dart b/lib/popups/accept_jobs_popup.dart new file mode 100644 index 0000000..3788203 --- /dev/null +++ b/lib/popups/accept_jobs_popup.dart @@ -0,0 +1,195 @@ +import 'package:expandable/expandable.dart'; +import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; +import 'package:isar/isar.dart'; +import 'package:kumi_popup_window/kumi_popup_window.dart'; +import 'package:stadtbote/main.dart'; +import 'package:stadtbote/model/job.dart'; +import 'package:stadtbote/tools/constants.dart'; +import 'package:stadtbote/tools/util.dart'; +import 'package:badges/badges.dart' as badges; + +void showAcceptJobsPopup(BuildContext context) async { + var entries = await _createListEntries(); + + showPopupWindow( + context, + //childSize:Size(240, MediaQuery.of(context).size.width * 0.8), + gravity: KumiPopupGravity.center, + //curve: Curves.elasticOut, + bgColor: Colors.grey.withOpacity(0.5), + clickOutDismiss: true, + clickBackDismiss: true, + customAnimation: false, + customPop: false, + customPage: false, + // targetRenderBox: (btnKey.currentContext.findRenderObject() as RenderBox), + //needSafeDisplay: true, + underStatusBar: false, + underAppBar: false, + //offsetX: -180, + //offsetY: 50, + duration: const Duration(milliseconds: 200), + onShowStart: (pop) {}, + onShowFinish: (pop) {}, + onDismissStart: (pop) {}, + onDismissFinish: (pop) {}, + onClickOut: (pop) {}, + onClickBack: (pop) {}, + childFun: (pop) { + _createListEntries(); + + return SizedBox( + key: GlobalKey(), + height: MediaQuery.of(context).size.height * 0.85, + width: MediaQuery.of(context).size.width * 0.85, + child: Container( + height: 100, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + color: Colors.white, + border: Border.all( + color: Colors.grey, + width: 0.5, + ), + ), + child: SingleChildScrollView(child: Column(children: entries)), + )); + }, + ); +} + +Future> _createListEntries() async { + List entries = []; + + var jobs = await MyApp.isarInstance.jobs.filter().stateEqualTo(0).findAll(); + jobs.addAll(await MyApp.isarInstance.jobs.filter().stateEqualTo(0).findAll()); + jobs.addAll(await MyApp.isarInstance.jobs.filter().stateEqualTo(0).findAll()); + jobs.addAll(await MyApp.isarInstance.jobs.filter().stateEqualTo(0).findAll()); + for (var job in jobs) { + entries.add(ExpandableNotifier( + child: ListTile( + contentPadding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8), + title: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + border: Border.all( + color: Constants.colorPrimary, + width: 1, + ), + ), + child: badges.Badge( + position: badges.BadgePosition.topEnd(top: -10, end: -5), + showBadge: true, + badgeContent: const Text( + 'Neu', + style: TextStyle( + color: Colors.white, + fontSize: 10.0, + ), + ), + badgeStyle: badges.BadgeStyle( + shape: badges.BadgeShape.square, + badgeColor: Colors.green, + padding: const EdgeInsets.all(5), + borderRadius: BorderRadius.circular(5), + borderSide: const BorderSide(color: Constants.colorPrimary, width: 0), + ), + child: Padding( + padding: const EdgeInsets.all(12.0), + child: Column( + children: [ + Text(DateFormat('dd.MM.yyyy HH:mm').format(DateTime.parse(job.ordertime)).toString(), textAlign: TextAlign.left), + Text('Auftragsnummer: ${job.id}'), + Text(job.tours[0].comp), + Text(job.tours[0].street), + Text(job.tours[0].city), + const SizedBox(height: 20), + ScrollOnExpand( + scrollOnExpand: true, + scrollOnCollapse: false, + child: ExpandablePanel( + theme: const ExpandableThemeData( + headerAlignment: ExpandablePanelHeaderAlignment.center, + tapBodyToCollapse: true, + ), + header: const Padding( + padding: EdgeInsets.all(0), + child: Text( + "Weitere Infos....", + style: TextStyle(fontSize: 15, color: Colors.black, fontWeight: FontWeight.bold), + )), + collapsed: SizedBox(), + expanded: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + height: 200, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + color: const Color(0xfffff4e4), + border: Border.all( + color: Colors.grey, + width: 0.5, + ), + ), + child: Text('asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd '), + ), + ], + ), + ), + ), + const SizedBox(height: 20), + Row(children: [ + Expanded( + child: getDefaultButton('Ablehnen', () => {_sendAnswer()}), + ), + const SizedBox(width: 20), + Expanded( + child: getDefaultButton('Annehmen', () => {}), + ) + ]) + ], + ), + ), + ), + ), + ), + )); + } + + return entries; +} + +/* +private void SendAnswer(int item) + { + JObject payloadObject; + + var location = App.CurrentLocation; + if (location != null) + payloadObject = new JObject( + new JProperty("reaction", new JObject( + new JProperty("id", _jobViewModel.IdString), + new JProperty("ver", _jobViewModel.Version), + new JProperty("item", item), + new JProperty("track", new JObject( + new JProperty("time", DateTime.Now.ToString("o")), + new JProperty("pos", new JObject( + new JProperty("lat", location.Latitude), + new JProperty("long", location.Longitude), + new JProperty("acc", location.Accuracy)))))))); + else + payloadObject = new JObject( + new JProperty("reaction", new JObject( + new JProperty("id", _jobViewModel.IdString), + new JProperty("ver", _jobViewModel.Version), + new JProperty("item", item), + new JProperty("track", new JObject( + new JProperty("time", DateTime.Now.ToString("o"))))))); + + App.Core.SendJsonMessageAsync("job", payloadObject); + } + */ + +_sendAnswer() {} diff --git a/pubspec.lock b/pubspec.lock index 6ec6b95..c3fe380 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -281,6 +281,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.0" + expandable: + dependency: "direct main" + description: + name: expandable + sha256: "9604d612d4d1146dafa96c6d8eec9c2ff0994658d6d09fed720ab788c7f5afc2" + url: "https://pub.dev" + source: hosted + version: "5.0.1" fake_async: dependency: transitive description: @@ -488,6 +496,54 @@ packages: url: "https://pub.dev" source: hosted version: "3.2.0" + geolocator: + dependency: "direct main" + description: + name: geolocator + sha256: e946395fc608842bb2f6c914807e9183f86f3cb787f6b8f832753e5251036f02 + url: "https://pub.dev" + source: hosted + version: "10.1.0" + geolocator_android: + dependency: transitive + description: + name: geolocator_android + sha256: "93906636752ea4d4e778afa981fdfe7409f545b3147046300df194330044d349" + url: "https://pub.dev" + source: hosted + version: "4.3.1" + geolocator_apple: + dependency: transitive + description: + name: geolocator_apple + sha256: "79babf44b692ec5e789d322dc736ef71586056e8e6828f747c9e005456b248bf" + url: "https://pub.dev" + source: hosted + version: "2.3.5" + geolocator_platform_interface: + dependency: transitive + description: + name: geolocator_platform_interface + sha256: "6c8d494d6948757c56720b778af742f6973f31fca1f702a7539b8917e4a2468a" + url: "https://pub.dev" + source: hosted + version: "4.2.0" + geolocator_web: + dependency: transitive + description: + name: geolocator_web + sha256: "59083f7e0871b78299918d92bf930a14377f711d2d1156c558cd5ebae6c20d58" + url: "https://pub.dev" + source: hosted + version: "2.2.0" + geolocator_windows: + dependency: transitive + description: + name: geolocator_windows + sha256: a92fae29779d5c6dc60e8411302f5221ade464968fe80a36d330e80a71f087af + url: "https://pub.dev" + source: hosted + version: "0.2.2" glob: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index dd8fe77..1a9e079 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -65,6 +65,8 @@ dependencies: signature: ^5.4.0 flutter_chat_types: ^3.6.2 flutter_chat_ui: ^1.6.10 + geolocator: ^10.1.0 + expandable: ^5.0.1 dev_dependencies: flutter_test: