Skip to content

Commit

Permalink
Address the following changes:
Browse files Browse the repository at this point in the history
feat: update interface
test: update interface test
test: update integration test
chore: update dependencies
  • Loading branch information
noxasch committed Apr 26, 2024
1 parent b9ec766 commit 408c60f
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void main() {
final res = await appWidgetPlugin.configureWidget(
androidPackageName: 'tech.noxasch.diff_name',
widgetId: 1,
widgetLayout: 'example_layout',
layoutId: 1,
payload: '{"itemId": 1, "stringUid": "uid"}',
url: 'https://google.come',
);
Expand All @@ -32,7 +32,7 @@ void main() {
final res = await appWidgetPlugin.updateWidget(
androidPackageName: 'tech.noxasch.diff_name',
widgetId: 1,
widgetLayout: 'example_layout',
layoutId: 1,
payload: '{"itemId": 1, "stringUid": "uid"}',
url: 'https://google.come',
textViews: {'widget_title': 'my title'},
Expand Down
4 changes: 2 additions & 2 deletions app_widget/example/integration_test/android_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void main() {
testWidgets('configureWidget', (tester) async {
final res = await appWidgetPlugin.configureWidget(
widgetId: 1,
widgetLayout: 'example_layout',
layoutId: 1,
payload: '{"itemId": 1, "stringUid": "uid"}',
url: 'https://google.come',
);
Expand All @@ -30,7 +30,7 @@ void main() {
testWidgets('updateWidget', (tester) async {
final res = await appWidgetPlugin.updateWidget(
widgetId: 1,
widgetLayout: 'example_layout',
layoutId: 1,
payload: '{"itemId": 1, "stringUid": "uid"}',
url: 'https://google.come',
textViews: {'widget_title': 'my title'},
Expand Down
4 changes: 2 additions & 2 deletions app_widget/example/integration_test/android_test_2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void main() {
testWidgets('configureWidget', (tester) async {
final res = await appWidgetPlugin.configureWidget(
widgetId: 1,
widgetLayout: 'example_layout',
layoutId: 1,
payload: '{"itemId": 1, "stringUid": "uid"}',
url: 'https://google.come',
);
Expand All @@ -28,7 +28,7 @@ void main() {
testWidgets('updateWidget', (tester) async {
final res = await appWidgetPlugin.updateWidget(
widgetId: 1,
widgetLayout: 'example_layout',
layoutId: 1,
payload: '{"itemId": 1, "stringUid": "uid"}',
url: 'https://google.come',
textViews: {'widget_title': 'my title'},
Expand Down
64 changes: 54 additions & 10 deletions app_widget/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ class MyApp extends StatefulWidget {

class _MyAppState extends State<MyApp> {
late final AppWidgetPlugin _appWidgetPlugin;
late final TextEditingController _controller;
late final TextEditingController _widgetIdcontroller;
late final TextEditingController _layoutIdcontroller;
late final TextEditingController _layoutNamecontroller;
int? _widgetId;
int? _layoutId;
String? _layoutName;

@override
void initState() {
Expand All @@ -35,17 +39,28 @@ class _MyAppState extends State<MyApp> {
onConfigureWidget: onConfigureWidget,
onClickWidget: onClickWidget,
);
_controller = TextEditingController();
_widgetIdcontroller = TextEditingController();
_layoutIdcontroller = TextEditingController();
_layoutNamecontroller = TextEditingController();
}

@override
void dispose() {
_controller.dispose();
_widgetIdcontroller.dispose();
_layoutIdcontroller.dispose();
_layoutNamecontroller.dispose();
super.dispose();
}

void onConfigureWidget(int widgetId) {
setState(() => _widgetId = widgetId);
void onConfigureWidget(int widgetId, int layoutId, String layoutName) {
setState(() {
_widgetId = widgetId;
_layoutId = layoutId;
_layoutName = layoutName;
});
_widgetIdcontroller.text = widgetId.toString();
_layoutIdcontroller.text = layoutId.toString();
_layoutNamecontroller.text = layoutName.toString();
// do something
}

Expand All @@ -65,20 +80,45 @@ class _MyAppState extends State<MyApp> {
padding: const EdgeInsets.all(30.0),
child: TextField(
decoration: const InputDecoration(label: Text('Widget Id')),
controller: _controller,
controller: _widgetIdcontroller,
keyboardType: TextInputType.number,
),
),
const SizedBox(
height: 10,
),
Padding(
padding: const EdgeInsets.all(30.0),
child: TextField(
decoration: const InputDecoration(label: Text('Layout Id')),
controller: _layoutIdcontroller,
readOnly: true,
),
),
const SizedBox(
height: 10,
),
Padding(
padding: const EdgeInsets.all(30.0),
child: TextField(
decoration:
const InputDecoration(label: Text('Layout Name')),
controller: _layoutNamecontroller,
readOnly: true,
),
),
const SizedBox(
height: 10,
),
ConfigureButton(
widgetId: _widgetId, appWidgetPlugin: _appWidgetPlugin),
widgetId: _widgetId,
layoutId: _layoutId,
appWidgetPlugin: _appWidgetPlugin),
const SizedBox(
height: 10,
),
WidgetExistButton(
controller: _controller,
controller: _widgetIdcontroller,
appWidgetPlugin: _appWidgetPlugin,
),
const SizedBox(
Expand All @@ -89,7 +129,8 @@ class _MyAppState extends State<MyApp> {
height: 10,
),
UpdateWidgetButton(
controller: _controller, appWidgetPlugin: _appWidgetPlugin),
controller: _widgetIdcontroller,
appWidgetPlugin: _appWidgetPlugin),
const SizedBox(
height: 10,
),
Expand Down Expand Up @@ -240,12 +281,15 @@ class ConfigureButton extends StatelessWidget {
const ConfigureButton({
Key? key,
required int? widgetId,
required int? layoutId,
required AppWidgetPlugin appWidgetPlugin,
}) : _widgetId = widgetId,
_layoutId = layoutId,
_appWidgetPlugin = appWidgetPlugin,
super(key: key);

final int? _widgetId;
final int? _layoutId;
final AppWidgetPlugin _appWidgetPlugin;

@override
Expand All @@ -259,7 +303,7 @@ class ConfigureButton extends StatelessWidget {
// send configure
await _appWidgetPlugin.configureWidget(
widgetId: _widgetId!,
widgetLayout: 'example_layout',
layoutId: _layoutId!,
textViews: {
'widget_title': 'App Widget',
'widget_message': 'Configured in flutter'
Expand Down
8 changes: 4 additions & 4 deletions app_widget/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ packages:
dependency: transitive
description:
name: app_widget_android
sha256: "9b5fc286e3f4add2404468035effbd584935e31b064b36228623f7b12678b77b"
sha256: "9a0aa193b373bf2e548d5af721e021b166f607ad932fc144334ce55b4ff40320"
url: "https://pub.dev"
source: hosted
version: "0.3.3"
version: "0.4.0"
app_widget_platform_interface:
dependency: transitive
description:
name: app_widget_platform_interface
sha256: "07c7500e83f86703fdad1aa3480e492a7226b322cbad3e71910f2630df96391e"
sha256: a288112ec826c25e7638ddc30c33a5e7279cfc2eadba89ccb33bc8d3ddbb589c
url: "https://pub.dev"
source: hosted
version: "0.3.1"
version: "0.4.0"
async:
dependency: transitive
description:
Expand Down
16 changes: 10 additions & 6 deletions app_widget/lib/src/app_widget_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class AppWidgetPlugin {
String? androidPackageName,

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

AppWidgetPlugin._({
required String? androidPackageName,
required void Function(int widgetId)? onConfigureWidget,
required void Function(int widgetId, int layoutId, String layoutName)?
onConfigureWidget,
required void Function(String? payload)? onClickWidget,
}) : _onConfigureWidget = onConfigureWidget,
_onClickWidget = onClickWidget,
Expand All @@ -62,7 +64,8 @@ class AppWidgetPlugin {
final String? _androidPackageName;

/// callback function when the widget is first created
final void Function(int widgetId)? _onConfigureWidget;
final void Function(int widgetId, int layoutId, String layoutName)?
_onConfigureWidget;

/// payload keys:
/// - itemId
Expand Down Expand Up @@ -100,7 +103,7 @@ class AppWidgetPlugin {
///
Future<bool?> configureWidget({
int? widgetId,
String? widgetLayout,
int? layoutId,
Map<String, String>? textViews = const {},
String? payload,
String? url,
Expand All @@ -109,7 +112,7 @@ class AppWidgetPlugin {
return AppWidgetPlatform.instance.configureWidget(
androidPackageName: androidPackageName ?? _androidPackageName,
widgetId: widgetId,
widgetLayout: widgetLayout,
layoutId: layoutId,
textViews: textViews,
payload: payload,
url: url,
Expand Down Expand Up @@ -177,6 +180,7 @@ class AppWidgetPlugin {
///
Future<bool?> updateWidget({
int? widgetId,
int? layoutId,
String? widgetLayout,
Map<String, String>? textViews = const {},
String? payload,
Expand All @@ -186,7 +190,7 @@ class AppWidgetPlugin {
return AppWidgetPlatform.instance.updateWidget(
androidPackageName: androidPackageName ?? _androidPackageName,
widgetId: widgetId,
widgetLayout: widgetLayout,
layoutId: layoutId,
textViews: textViews,
payload: payload,
url: url,
Expand Down
4 changes: 2 additions & 2 deletions app_widget/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ dependencies:
flutter:
sdk: flutter
plugin_platform_interface: ^2.1.7
app_widget_platform_interface: ^0.3.1
app_widget_android: ^0.3.3
app_widget_platform_interface: ^0.4.0
app_widget_android: ^0.4.0
# app_widget_platform_interface: # local dev
# path: ../app_widget_platform_interface
# app_widget_android: # local dev
Expand Down
17 changes: 9 additions & 8 deletions app_widget/test/app_widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';

// NOTE: this merely test platform specific (android) interface
void main() {
TestWidgetsFlutterBinding.ensureInitialized();

Expand Down Expand Up @@ -54,7 +55,7 @@ void main() {
expect(
appWidgetPlugin.configureWidget(
widgetId: 1,
widgetLayout: 'layoutname',
layoutId: 1,
payload: '{"itemId": 1, "stringUid": "uid"}',
url: 'https://google.come',
),
Expand All @@ -67,7 +68,7 @@ void main() {
arguments: <String, Object>{
'androidPackageName': 'appname',
'widgetId': 1,
'widgetLayout': 'layoutname',
'layoutId': 1,
'textViews': {},
'payload': '{"itemId": 1, "stringUid": "uid"}',
'url': 'https://google.come',
Expand All @@ -84,7 +85,7 @@ void main() {
expect(
appWidgetPlugin.configureWidget(
widgetId: 1,
widgetLayout: 'layoutname',
layoutId: 1,
payload: '{"itemId": 1, "stringUid": "uid"}',
url: 'https://google.come',
androidPackageName: 'appname2',
Expand All @@ -98,7 +99,7 @@ void main() {
arguments: <String, Object>{
'androidPackageName': 'appname2',
'widgetId': 1,
'widgetLayout': 'layoutname',
'layoutId': 1,
'textViews': {},
'payload': '{"itemId": 1, "stringUid": "uid"}',
'url': 'https://google.come',
Expand All @@ -115,7 +116,7 @@ void main() {
expect(
appWidgetPlugin.updateWidget(
widgetId: 1,
widgetLayout: 'layoutname',
layoutId: 1,
payload: '{"itemId": 1, "stringUid": "uid"}',
url: 'https://google.come',
),
Expand All @@ -128,7 +129,7 @@ void main() {
arguments: <String, Object>{
'androidPackageName': 'appname',
'widgetId': 1,
'widgetLayout': 'layoutname',
'layoutId': 1,
'textViews': {},
'payload': '{"itemId": 1, "stringUid": "uid"}',
'url': 'https://google.come',
Expand All @@ -146,7 +147,7 @@ void main() {
appWidgetPlugin.updateWidget(
androidPackageName: 'appname2',
widgetId: 1,
widgetLayout: 'layoutname',
layoutId: 1,
payload: '{"itemId": 1, "stringUid": "uid"}',
url: 'https://google.come',
),
Expand All @@ -159,7 +160,7 @@ void main() {
arguments: <String, Object>{
'androidPackageName': 'appname2',
'widgetId': 1,
'widgetLayout': 'layoutname',
'layoutId': 1,
'textViews': {},
'payload': '{"itemId": 1, "stringUid": "uid"}',
'url': 'https://google.come',
Expand Down
1 change: 1 addition & 0 deletions app_widget_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +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.3
* fix: fix trigger update widget updating the widget multiple time

Expand Down

0 comments on commit 408c60f

Please sign in to comment.