diff --git a/.huskyrc b/.huskyrc
new file mode 100644
index 0000000..0926705
--- /dev/null
+++ b/.huskyrc
@@ -0,0 +1 @@
+export PATH="/usr/local/bin:$PATH"
\ No newline at end of file
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 8c4a410..1a2342e 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -26,7 +26,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ val views = RemoteViews(context.packageName, R.layout.widget_layout).apply {
+
+ // Open App on Widget Click
+ val pendingIntent = HomeWidgetLaunchIntent.getActivity(context,
+ MainActivity::class.java)
+ setOnClickPendingIntent(R.id.widget_root, pendingIntent)
+
+ setTextViewText(R.id.obed, widgetData.getString("_obed", "Nic"))
+
+ // Pending intent to update counter on button click
+ val backgroundIntent = HomeWidgetBackgroundIntent.getBroadcast(context,
+ Uri.parse("myAppWidget://update"))
+ setOnClickPendingIntent(R.id.bt_update, backgroundIntent)
+ }
+ appWidgetManager.updateAppWidget(widgetId, views)
+ }
+ }
+}
\ No newline at end of file
diff --git a/android/app/src/main/res/layout/widget_layout.xml b/android/app/src/main/res/layout/widget_layout.xml
new file mode 100644
index 0000000..0f480c1
--- /dev/null
+++ b/android/app/src/main/res/layout/widget_layout.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/app/src/main/res/xml/widget_info.xml b/android/app/src/main/res/xml/widget_info.xml
new file mode 100644
index 0000000..6b04bf3
--- /dev/null
+++ b/android/app/src/main/res/xml/widget_info.xml
@@ -0,0 +1,8 @@
+
\ No newline at end of file
diff --git a/lib/main.dart b/lib/main.dart
index 28b70eb..897dcca 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -4,6 +4,7 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
+import 'package:home_widget/home_widget.dart';
import 'package:opencanteen/lang/lang_cz.dart';
import 'package:opencanteen/loginmanager.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
@@ -35,9 +36,32 @@ Copyright (C) 2022 Matyáš Caras a přispěvatelé
*/
void main() {
+ WidgetsFlutterBinding.ensureInitialized();
+ HomeWidget.registerBackgroundCallback(backgroundCallback);
runApp(const MyApp());
}
+/// Volá se na práci s widgetem
+void backgroundCallback(Uri? uri) async {
+ if (uri != null && uri.host == 'update') {
+ String _obed = "Nic";
+ var d = await LoginManager.getDetails();
+ if (d != null) {
+ var c = Canteen(d["url"]!);
+ await c.login(d["user"]!, d["pass"]!);
+ var j = await c.jidelnicekDen();
+ try {
+ _obed = j.jidla.singleWhere((element) => element.objednano).nazev;
+ } catch (_) {
+ _obed = "Nic";
+ }
+ }
+ await HomeWidget.saveWidgetData('_obed', _obed);
+ await HomeWidget.updateWidget(
+ name: 'AppWidgetProvider', iOSName: 'AppWidgetProvider');
+ }
+}
+
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
diff --git a/pubspec.lock b/pubspec.lock
index da74db2..72078d9 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -205,6 +205,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
+ home_widget:
+ dependency: "direct main"
+ description:
+ name: home_widget
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "0.1.6"
http:
dependency: transitive
description:
diff --git a/pubspec.yaml b/pubspec.yaml
index ed5d01a..3ece552 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -6,7 +6,7 @@ publish_to: 'none'
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
-version: 1.1.1+5
+version: 1.2.0+8
environment:
sdk: ">=2.16.1 <3.0.0"
@@ -23,6 +23,7 @@ dependencies:
path_provider: ^2.0.9
shared_preferences: ^2.0.13
introduction_screen: ^3.0.1
+ home_widget: ^0.1.6
dev_dependencies:
flutter_lints: ^1.0.0