Skip to content

Commit 90596f3

Browse files
authored
Merge pull request #26 from noxasch/feat/android-forward-layoutname-layoutid
feat(android): forward layout id and name
2 parents 8a69de6 + 06d1e14 commit 90596f3

File tree

18 files changed

+145
-70
lines changed

18 files changed

+145
-70
lines changed

app_widget/example/integration_test/android_diff_package_name_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void main() {
1515
final res = await appWidgetPlugin.configureWidget(
1616
androidPackageName: 'tech.noxasch.diff_name',
1717
widgetId: 1,
18-
widgetLayout: 'example_layout',
18+
layoutId: 1,
1919
payload: '{"itemId": 1, "stringUid": "uid"}',
2020
url: 'https://google.come',
2121
);
@@ -32,7 +32,7 @@ void main() {
3232
final res = await appWidgetPlugin.updateWidget(
3333
androidPackageName: 'tech.noxasch.diff_name',
3434
widgetId: 1,
35-
widgetLayout: 'example_layout',
35+
layoutId: 1,
3636
payload: '{"itemId": 1, "stringUid": "uid"}',
3737
url: 'https://google.come',
3838
textViews: {'widget_title': 'my title'},

app_widget/example/integration_test/android_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void main() {
1414
testWidgets('configureWidget', (tester) async {
1515
final res = await appWidgetPlugin.configureWidget(
1616
widgetId: 1,
17-
widgetLayout: 'example_layout',
17+
layoutId: 1,
1818
payload: '{"itemId": 1, "stringUid": "uid"}',
1919
url: 'https://google.come',
2020
);
@@ -30,7 +30,7 @@ void main() {
3030
testWidgets('updateWidget', (tester) async {
3131
final res = await appWidgetPlugin.updateWidget(
3232
widgetId: 1,
33-
widgetLayout: 'example_layout',
33+
layoutId: 1,
3434
payload: '{"itemId": 1, "stringUid": "uid"}',
3535
url: 'https://google.come',
3636
textViews: {'widget_title': 'my title'},

app_widget/example/integration_test/android_test_2.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void main() {
1212
testWidgets('configureWidget', (tester) async {
1313
final res = await appWidgetPlugin.configureWidget(
1414
widgetId: 1,
15-
widgetLayout: 'example_layout',
15+
layoutId: 1,
1616
payload: '{"itemId": 1, "stringUid": "uid"}',
1717
url: 'https://google.come',
1818
);
@@ -28,7 +28,7 @@ void main() {
2828
testWidgets('updateWidget', (tester) async {
2929
final res = await appWidgetPlugin.updateWidget(
3030
widgetId: 1,
31-
widgetLayout: 'example_layout',
31+
layoutId: 1,
3232
payload: '{"itemId": 1, "stringUid": "uid"}',
3333
url: 'https://google.come',
3434
textViews: {'widget_title': 'my title'},

app_widget/example/lib/main.dart

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ class MyApp extends StatefulWidget {
2424

2525
class _MyAppState extends State<MyApp> {
2626
late final AppWidgetPlugin _appWidgetPlugin;
27-
late final TextEditingController _controller;
27+
late final TextEditingController _widgetIdcontroller;
28+
late final TextEditingController _layoutIdcontroller;
29+
late final TextEditingController _layoutNamecontroller;
2830
int? _widgetId;
31+
int? _layoutId;
32+
// ignore: unused_field
33+
String? _layoutName;
2934

3035
@override
3136
void initState() {
@@ -35,17 +40,28 @@ class _MyAppState extends State<MyApp> {
3540
onConfigureWidget: onConfigureWidget,
3641
onClickWidget: onClickWidget,
3742
);
38-
_controller = TextEditingController();
43+
_widgetIdcontroller = TextEditingController();
44+
_layoutIdcontroller = TextEditingController();
45+
_layoutNamecontroller = TextEditingController();
3946
}
4047

4148
@override
4249
void dispose() {
43-
_controller.dispose();
50+
_widgetIdcontroller.dispose();
51+
_layoutIdcontroller.dispose();
52+
_layoutNamecontroller.dispose();
4453
super.dispose();
4554
}
4655

47-
void onConfigureWidget(int widgetId) {
48-
setState(() => _widgetId = widgetId);
56+
void onConfigureWidget(int widgetId, int layoutId, String layoutName) {
57+
setState(() {
58+
_widgetId = widgetId;
59+
_layoutId = layoutId;
60+
_layoutName = layoutName;
61+
});
62+
_widgetIdcontroller.text = widgetId.toString();
63+
_layoutIdcontroller.text = layoutId.toString();
64+
_layoutNamecontroller.text = layoutName.toString();
4965
// do something
5066
}
5167

@@ -65,20 +81,45 @@ class _MyAppState extends State<MyApp> {
6581
padding: const EdgeInsets.all(30.0),
6682
child: TextField(
6783
decoration: const InputDecoration(label: Text('Widget Id')),
68-
controller: _controller,
84+
controller: _widgetIdcontroller,
6985
keyboardType: TextInputType.number,
7086
),
7187
),
7288
const SizedBox(
7389
height: 10,
7490
),
91+
Padding(
92+
padding: const EdgeInsets.all(30.0),
93+
child: TextField(
94+
decoration: const InputDecoration(label: Text('Layout Id')),
95+
controller: _layoutIdcontroller,
96+
readOnly: true,
97+
),
98+
),
99+
const SizedBox(
100+
height: 10,
101+
),
102+
Padding(
103+
padding: const EdgeInsets.all(30.0),
104+
child: TextField(
105+
decoration:
106+
const InputDecoration(label: Text('Layout Name')),
107+
controller: _layoutNamecontroller,
108+
readOnly: true,
109+
),
110+
),
111+
const SizedBox(
112+
height: 10,
113+
),
75114
ConfigureButton(
76-
widgetId: _widgetId, appWidgetPlugin: _appWidgetPlugin),
115+
widgetId: _widgetId,
116+
layoutId: _layoutId,
117+
appWidgetPlugin: _appWidgetPlugin),
77118
const SizedBox(
78119
height: 10,
79120
),
80121
WidgetExistButton(
81-
controller: _controller,
122+
controller: _widgetIdcontroller,
82123
appWidgetPlugin: _appWidgetPlugin,
83124
),
84125
const SizedBox(
@@ -89,7 +130,8 @@ class _MyAppState extends State<MyApp> {
89130
height: 10,
90131
),
91132
UpdateWidgetButton(
92-
controller: _controller, appWidgetPlugin: _appWidgetPlugin),
133+
controller: _widgetIdcontroller,
134+
appWidgetPlugin: _appWidgetPlugin),
93135
const SizedBox(
94136
height: 10,
95137
),
@@ -240,12 +282,15 @@ class ConfigureButton extends StatelessWidget {
240282
const ConfigureButton({
241283
Key? key,
242284
required int? widgetId,
285+
required int? layoutId,
243286
required AppWidgetPlugin appWidgetPlugin,
244287
}) : _widgetId = widgetId,
288+
_layoutId = layoutId,
245289
_appWidgetPlugin = appWidgetPlugin,
246290
super(key: key);
247291

248292
final int? _widgetId;
293+
final int? _layoutId;
249294
final AppWidgetPlugin _appWidgetPlugin;
250295

251296
@override
@@ -259,7 +304,7 @@ class ConfigureButton extends StatelessWidget {
259304
// send configure
260305
await _appWidgetPlugin.configureWidget(
261306
widgetId: _widgetId!,
262-
widgetLayout: 'example_layout',
307+
layoutId: _layoutId!,
263308
textViews: {
264309
'widget_title': 'App Widget',
265310
'widget_message': 'Configured in flutter'

app_widget/example/pubspec.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ packages:
1212
dependency: transitive
1313
description:
1414
name: app_widget_android
15-
sha256: "9b5fc286e3f4add2404468035effbd584935e31b064b36228623f7b12678b77b"
15+
sha256: "9a0aa193b373bf2e548d5af721e021b166f607ad932fc144334ce55b4ff40320"
1616
url: "https://pub.dev"
1717
source: hosted
18-
version: "0.3.3"
18+
version: "0.4.0"
1919
app_widget_platform_interface:
2020
dependency: transitive
2121
description:
2222
name: app_widget_platform_interface
23-
sha256: "07c7500e83f86703fdad1aa3480e492a7226b322cbad3e71910f2630df96391e"
23+
sha256: a288112ec826c25e7638ddc30c33a5e7279cfc2eadba89ccb33bc8d3ddbb589c
2424
url: "https://pub.dev"
2525
source: hosted
26-
version: "0.3.1"
26+
version: "0.4.0"
2727
async:
2828
dependency: transitive
2929
description:

app_widget/lib/src/app_widget_plugin.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class AppWidgetPlugin {
2424
String? androidPackageName,
2525

2626
/// callback function when the widget is first created
27-
void Function(int widgetId)? onConfigureWidget,
27+
void Function(int widgetId, int layoutId, String layoutName)?
28+
onConfigureWidget,
2829
void Function(String? payload)? onClickWidget,
2930
}) {
3031
if (instance != null) return instance!;
@@ -39,7 +40,8 @@ class AppWidgetPlugin {
3940

4041
AppWidgetPlugin._({
4142
required String? androidPackageName,
42-
required void Function(int widgetId)? onConfigureWidget,
43+
required void Function(int widgetId, int layoutId, String layoutName)?
44+
onConfigureWidget,
4345
required void Function(String? payload)? onClickWidget,
4446
}) : _onConfigureWidget = onConfigureWidget,
4547
_onClickWidget = onClickWidget,
@@ -62,7 +64,8 @@ class AppWidgetPlugin {
6264
final String? _androidPackageName;
6365

6466
/// callback function when the widget is first created
65-
final void Function(int widgetId)? _onConfigureWidget;
67+
final void Function(int widgetId, int layoutId, String layoutName)?
68+
_onConfigureWidget;
6669

6770
/// payload keys:
6871
/// - itemId
@@ -100,7 +103,7 @@ class AppWidgetPlugin {
100103
///
101104
Future<bool?> configureWidget({
102105
int? widgetId,
103-
String? widgetLayout,
106+
int? layoutId,
104107
Map<String, String>? textViews = const {},
105108
String? payload,
106109
String? url,
@@ -109,7 +112,7 @@ class AppWidgetPlugin {
109112
return AppWidgetPlatform.instance.configureWidget(
110113
androidPackageName: androidPackageName ?? _androidPackageName,
111114
widgetId: widgetId,
112-
widgetLayout: widgetLayout,
115+
layoutId: layoutId,
113116
textViews: textViews,
114117
payload: payload,
115118
url: url,
@@ -177,6 +180,7 @@ class AppWidgetPlugin {
177180
///
178181
Future<bool?> updateWidget({
179182
int? widgetId,
183+
int? layoutId,
180184
String? widgetLayout,
181185
Map<String, String>? textViews = const {},
182186
String? payload,
@@ -186,7 +190,7 @@ class AppWidgetPlugin {
186190
return AppWidgetPlatform.instance.updateWidget(
187191
androidPackageName: androidPackageName ?? _androidPackageName,
188192
widgetId: widgetId,
189-
widgetLayout: widgetLayout,
193+
layoutId: layoutId,
190194
textViews: textViews,
191195
payload: payload,
192196
url: url,

app_widget/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ dependencies:
1313
flutter:
1414
sdk: flutter
1515
plugin_platform_interface: ^2.1.7
16-
app_widget_platform_interface: ^0.3.1
17-
app_widget_android: ^0.3.3
16+
app_widget_platform_interface: ^0.4.0
17+
app_widget_android: ^0.4.0
1818
# app_widget_platform_interface: # local dev
1919
# path: ../app_widget_platform_interface
2020
# app_widget_android: # local dev

app_widget/test/app_widget_test.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:flutter/foundation.dart';
66
import 'package:flutter/services.dart';
77
import 'package:flutter_test/flutter_test.dart';
88

9+
// NOTE: this merely test platform specific (android) interface
910
void main() {
1011
TestWidgetsFlutterBinding.ensureInitialized();
1112

@@ -54,7 +55,7 @@ void main() {
5455
expect(
5556
appWidgetPlugin.configureWidget(
5657
widgetId: 1,
57-
widgetLayout: 'layoutname',
58+
layoutId: 1,
5859
payload: '{"itemId": 1, "stringUid": "uid"}',
5960
url: 'https://google.come',
6061
),
@@ -67,7 +68,7 @@ void main() {
6768
arguments: <String, Object>{
6869
'androidPackageName': 'appname',
6970
'widgetId': 1,
70-
'widgetLayout': 'layoutname',
71+
'layoutId': 1,
7172
'textViews': {},
7273
'payload': '{"itemId": 1, "stringUid": "uid"}',
7374
'url': 'https://google.come',
@@ -84,7 +85,7 @@ void main() {
8485
expect(
8586
appWidgetPlugin.configureWidget(
8687
widgetId: 1,
87-
widgetLayout: 'layoutname',
88+
layoutId: 1,
8889
payload: '{"itemId": 1, "stringUid": "uid"}',
8990
url: 'https://google.come',
9091
androidPackageName: 'appname2',
@@ -98,7 +99,7 @@ void main() {
9899
arguments: <String, Object>{
99100
'androidPackageName': 'appname2',
100101
'widgetId': 1,
101-
'widgetLayout': 'layoutname',
102+
'layoutId': 1,
102103
'textViews': {},
103104
'payload': '{"itemId": 1, "stringUid": "uid"}',
104105
'url': 'https://google.come',
@@ -115,7 +116,7 @@ void main() {
115116
expect(
116117
appWidgetPlugin.updateWidget(
117118
widgetId: 1,
118-
widgetLayout: 'layoutname',
119+
layoutId: 1,
119120
payload: '{"itemId": 1, "stringUid": "uid"}',
120121
url: 'https://google.come',
121122
),
@@ -128,7 +129,7 @@ void main() {
128129
arguments: <String, Object>{
129130
'androidPackageName': 'appname',
130131
'widgetId': 1,
131-
'widgetLayout': 'layoutname',
132+
'layoutId': 1,
132133
'textViews': {},
133134
'payload': '{"itemId": 1, "stringUid": "uid"}',
134135
'url': 'https://google.come',
@@ -146,7 +147,7 @@ void main() {
146147
appWidgetPlugin.updateWidget(
147148
androidPackageName: 'appname2',
148149
widgetId: 1,
149-
widgetLayout: 'layoutname',
150+
layoutId: 1,
150151
payload: '{"itemId": 1, "stringUid": "uid"}',
151152
url: 'https://google.come',
152153
),
@@ -159,7 +160,7 @@ void main() {
159160
arguments: <String, Object>{
160161
'androidPackageName': 'appname2',
161162
'widgetId': 1,
162-
'widgetLayout': 'layoutname',
163+
'layoutId': 1,
163164
'textViews': {},
164165
'payload': '{"itemId": 1, "stringUid": "uid"}',
165166
'url': 'https://google.come',

app_widget_android/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.4.0
2+
* breaking changes: `configureWidget` and `updateWidget` accept `layoutId` instead of `layoutName`
3+
* breaking changes: `onConfigureWidget` now accept 3 params (`widgetId`, `layoutId`, `layoutName`)
14

25
## 0.3.3
36
* fix: fix trigger update widget updating the widget multiple time

0 commit comments

Comments
 (0)