Skip to content

Commit

Permalink
chore: bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
noxasch committed Apr 26, 2024
1 parent 90596f3 commit 54a346c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
4 changes: 4 additions & 0 deletions app_widget/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.0
* breaking changes: `configureWidget` and `updateWidget` accept `layoutId` instead of `layoutName`
* breaking changes: `onConfigureWidget` now accept 3 params (`widgetId`, `layoutId`, `layoutName`)

## 0.3.1
* fix(android): fix trigger update widget updating the widget multiple time

Expand Down
34 changes: 25 additions & 9 deletions app_widget/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ and can be manage fully from flutter side keeping app codebase logic in flutter.
| --- | --- |
|![screen_shot](assets/screen_shot.webp) | ![gif](assets/example_app.gif) |

## Caveat
## Note
- Please see the changelogs for breaking changes
- Every minor version update might introduce a breaking changes as this plugin is still considered alpha

## Caveats

Configuring or opening a screen from the widget is slower (unless the app is still active in the background)
compare to native because we need to wait for flutter engine to start. Hence as you can see from the gif there
Expand All @@ -23,6 +27,8 @@ So this shouldn't be an issue. Although we can notice significant delay in old p

## Plaform Support

As of current state I have no capacity to support for iOS, but help is welcome.

| Android | iOS |
| :-----: | :-: |
| ✔️ | |
Expand Down Expand Up @@ -211,10 +217,14 @@ await appWidgetPlugin.configureWidget(...)
```dart
// this method can be declare as a top level function or inside a widget as a member function
@pragma('vm:entry-point')
void onConfigureWidget(int widgetId) async {
void onConfigureWidget(int widgetId, int layoutId, String layoutName) async {
// handle widget configuration
// eg:
// redirect or use launchUrl and deeplink redirect to configuration page
// store widgetId, layoutId and layoutName in sharedPref
// use layoutName to build proper payload
// layoutName: tech.noxasch.app_widget_example:layout/example_layout
}
// onConfigureWidget callback are optional
Expand All @@ -229,7 +239,7 @@ final appWidgetPlugin = AppWidgetPlugin(
await appWidgetPlugin.configureWidget(
// change to androidPackageName - we needed as param since there is no standard on how long the domain name can be
widgetId: _widgetId!,
widgetLayout: 'example_layout',
layoutId: _layoutId!,
textViews: {
'widget_title': 'MY WIDGET',
'widget_message': 'This is my widget message'
Expand Down Expand Up @@ -264,7 +274,9 @@ final appWidgetPlugin = AppWidgetPlugin(
```

#### updateWidget
Make sure you store the `widgetId` during widget configuration.
Make sure you store the `widgetId` and `layoutId` during widget configuration.

Tips: Store `layoutName` to easily manage payload textViews for multiple layout

Most of the time you'll want to update widget via workmanager. See [below](#handling-widget-update-using-in-flutter-workmanger)
how to use the plugin in workmanager.
Expand Down Expand Up @@ -325,9 +337,10 @@ inside the callback.
```dart
// Using workmanager chained OneOffTask
@pragma('vm:entry-point')
void onConfigureWidget(int widgetId) async {
void onConfigureWidget(int widgetId, int layoutId) async {
final sharedPrefs = await SharedPreferences.getInstance();
await sharedPrefs.setInt('widget_id', widgetId);
await sharedPrefs.setInt('layout_id', layoutId);
// register task druing configure event in onConfigure callback
await Workmanager().registerOneOffTask(
'UpdateMyWidget',
Expand All @@ -353,6 +366,7 @@ void onConfigureWidget(int widgetId) async {
void onConfigureWidget(int widgetId) async {
final sharedPrefs = await SharedPreferences.getInstance();
await sharedPrefs.setInt('widget_id', widgetId);
await sharedPrefs.setInt('layout_id', layoutId);
// register task druing configure event in onConfigure callback
await Workmanager().registerPeriodicTask(
'$kUpdateWidgetTask-$widgetId',
Expand All @@ -367,6 +381,7 @@ void onConfigureWidget(int widgetId) async {
initialDelay: const Duration(minutes: kWidgetUpdateIntervalInMinutes),
inputData: {
'widgetId': widgetId,
'layoutId': layoutId,
'payload': payload,
},
);
Expand Down Expand Up @@ -404,11 +419,12 @@ Future<void> updateWidgetWorker() async {
final repo = db.todosRepository;
final widgetId = sharedPrefs.getInt('widget_id');
final layoutId = sharedPrefs.getInt('layout_id');
if (widgetId != null) {
await appWidgetPlugin.updateWidget(
widgetId: _widgetId!,
widgetLayout: 'example_layout',
widgetId: widgetId!,
layoutId: layoutId,
textViews: {
'widget_title': 'MY WIDGET',
'widget_message': 'This is my widget message'
Expand Down Expand Up @@ -503,14 +519,14 @@ void main() {
...
), isTrue);
// testing if your method that call configureWidget sending the expected argumetns
// testing if your method that call configureWidget sending the expected arguments - interface level only
expect(log, <Matcher>[
isMethodCall(
'configureWidget',
arguments: <String, Object>{
'androidPackageName': 'appname', // androidPackageName is included behind the scene
'widgetId': 1,
'widgetLayout': 'layoutname',
'layoutId': 1,
'textViews': {},
'payload': '{"itemId": 1, "stringUid": "uid"}'
},
Expand Down
2 changes: 1 addition & 1 deletion app_widget/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: app_widget
description: Flutter plugin to manage app widget / home screen widget from within flutter app.
version: 0.3.1
version: 0.4.0
homepage: https://noxasch.tech/
repository: https://github.com/noxasch/flutter_app_widget/tree/master/app_widget
issue_tracker: https://github.com/noxasch/flutter_app_widget/issues
Expand Down

0 comments on commit 54a346c

Please sign in to comment.