Surface/lib/providers/widget.dart

37 lines
1.1 KiB
Dart
Raw Normal View History

2024-12-14 10:18:13 +00:00
import 'dart:convert';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:home_widget/home_widget.dart';
class HomeWidgetProvider {
HomeWidgetProvider(BuildContext context);
Future<void> initialize() async {
if (kIsWeb || !(Platform.isAndroid || Platform.isIOS)) return;
if (!kIsWeb && Platform.isIOS) {
await HomeWidget.setAppGroupId("group.solsynth.solian");
}
}
2024-12-14 16:52:42 +00:00
Future<void> saveWidgetData(String id, dynamic data, {bool update = true}) async {
2024-12-14 10:18:13 +00:00
if (kIsWeb || !(Platform.isAndroid || Platform.isIOS)) return;
await HomeWidget.saveWidgetData(id, jsonEncode(data));
2024-12-14 16:52:42 +00:00
if (update) await updateWidget();
2024-12-14 10:18:13 +00:00
}
Future<void> updateWidget() async {
if (kIsWeb || !(Platform.isAndroid || Platform.isIOS)) return;
2024-12-14 16:52:42 +00:00
const widgets = ["SolarFeaturedPostWidget", "SolarCheckInWidget"];
for(final widget in widgets) {
await HomeWidget.updateWidget(
name: widget,
iOSName: widget,
androidName: "com.solsynth.solian.$widget",
qualifiedAndroidName: "group.solsynth.solian.$widget",
);
}
2024-12-14 10:18:13 +00:00
}
}