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 49bb8be..e6109eb 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -28,7 +28,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 2adb7f6..cae98d6 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.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';
@@ -36,9 +37,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 fde98a3..54340c0 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -8,6 +8,7 @@ publish_to: 'none'
# followed by an optional build number separated by a +.
version: 1.2.0+14
+
environment:
sdk: ">=2.16.1 <3.0.0"
@@ -23,6 +24,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