Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1dd8325
Moved quickactions to a subfolder
danielroek Mar 17, 2021
b1314ef
Added platform interface with tests
danielroek Mar 19, 2021
bc99e6f
Merge remote-tracking branch 'flutter/master' into quick_actions_fede…
danielroek Mar 19, 2021
7ca0785
Merge remote-tracking branch 'origin/quick_actions_federated' into qu…
danielroek Mar 19, 2021
836bc78
Added exports
danielroek Mar 19, 2021
4b3c09f
WIP: quick_action tests
danielroek Mar 19, 2021
0f79c71
Formatted, made initialize return Future<void> instead of void
danielroek Mar 19, 2021
77d4eaa
WIP: quick_action tests
danielroek Mar 19, 2021
e5c4836
Merge remote-tracking branch 'origin/quick_actions_federated_migratio…
danielroek Mar 19, 2021
3d77603
Fixed tests
danielroek Mar 19, 2021
357db7e
Fixed formatting
danielroek Mar 19, 2021
9ea2dd9
Merge branch 'quick_actions_federated_platform_interface' into quick_…
danielroek Mar 19, 2021
9c68b66
fixed path
danielroek Mar 19, 2021
d942293
formatting
danielroek Mar 19, 2021
da5f028
Fixed analyze issue with import
danielroek Mar 19, 2021
3727f61
Fixed formatting
danielroek Mar 19, 2021
d4ba462
Merge branch 'quick_actions_federated_platform_interface' into quick_…
danielroek Mar 19, 2021
f0652c8
Removed AUTHORS from quick_actions folder
danielroek Mar 19, 2021
e50b657
added meta to pubspec
danielroek Mar 19, 2021
1e6624d
Fixed formatting
danielroek Mar 19, 2021
4b7251b
Merge branch 'quick_actions_federated_platform_interface' into quick_…
danielroek Mar 19, 2021
343effe
Added license in files
danielroek Mar 19, 2021
f73a1cb
Added license in files
danielroek Mar 19, 2021
c0f3dec
fixed version in pubspec
danielroek Mar 19, 2021
c9fbf5a
Removed accidental \\\
danielroek Mar 19, 2021
3f56653
Merge branch 'quick_actions_federated_platform_interface' into quick_…
danielroek Mar 19, 2021
a3524b9
changed license to Flutter 2017
danielroek Mar 19, 2021
b6da72f
Merge branch 'quick_actions_federated_platform_interface' into quick_…
danielroek Mar 19, 2021
4863399
Merge branch 'master' into quick_actions_federated_migration
danielroek Mar 24, 2021
f3e71b0
Added quick_action files
danielroek Mar 24, 2021
648e1c2
Fixed formatting
danielroek Mar 24, 2021
32550d8
Removed WidgetsFlutterBinding
danielroek Mar 24, 2021
ed83e5d
Reverted bumping Flutter version
danielroek Mar 24, 2021
c4d0cf4
Removed unused import
danielroek Mar 24, 2021
6826e4d
Merge branch 'master' into quick_actions_federated_migration
danielroek Mar 25, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ Aleksandr Yurkovskiy <sanekyy@gmail.com>
Anton Borries <mail@antonborri.es>
Alex Li <google@alexv525.com>
Rahul Raj <64.rahulraj@gmail.com>
Daniel Roek <daniel.roek@gmail.com>
4 changes: 4 additions & 0 deletions packages/quick_actions/quick_actions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.0

* Migrate to federated architecture.

## 0.5.0+1

* Updated example app implementation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void main() {

testWidgets('Can set shortcuts', (WidgetTester tester) async {
final QuickActions quickActions = QuickActions();
quickActions.initialize(null);
await quickActions.initialize(null);

const ShortcutItem shortCutItem = ShortcutItem(
type: 'action_one',
Expand Down
82 changes: 8 additions & 74 deletions packages/quick_actions/quick_actions/lib/quick_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,90 +4,24 @@

import 'dart:async';

import 'package:flutter/services.dart';
import 'package:meta/meta.dart';
import 'package:quick_actions_platform_interface/platform_interface/quick_actions_platform.dart';
import 'package:quick_actions_platform_interface/types/types.dart';

const MethodChannel _kChannel =
MethodChannel('plugins.flutter.io/quick_actions');

/// Handler for a quick action launch event.
///
/// The argument [type] corresponds to the [ShortcutItem]'s field.
typedef void QuickActionHandler(String type);

/// Home screen quick-action shortcut item.
class ShortcutItem {
/// Constructs an instance with the given [type], [localizedTitle], and
/// [icon].
///
/// Only [icon] should be nullable. It will remain `null` if unset.
const ShortcutItem({
required this.type,
required this.localizedTitle,
this.icon,
});

/// The identifier of this item; should be unique within the app.
final String type;

/// Localized title of the item.
final String localizedTitle;

/// Name of native resource (xcassets etc; NOT a Flutter asset) to be
/// displayed as the icon for this item.
final String? icon;
}
export 'package:quick_actions_platform_interface/types/types.dart';

/// Quick actions plugin.
class QuickActions {
/// Gets an instance of the plugin with the default methodChannel.
///
/// [initialize] should be called before using any other methods.
factory QuickActions() => _instance;

/// This is a test-only constructor. Do not call this, it can break at any
/// time.
@visibleForTesting
QuickActions.withMethodChannel(this.channel);

static final QuickActions _instance =
QuickActions.withMethodChannel(_kChannel);

/// This is a test-only accessor. Do not call this, it can break at any time.
@visibleForTesting
final MethodChannel channel;

/// Initializes this plugin.
///
/// Call this once before any further interaction with the the plugin.
void initialize(QuickActionHandler handler) async {
channel.setMethodCallHandler((MethodCall call) async {
assert(call.method == 'launch');
handler(call.arguments);
});
final String? action =
await channel.invokeMethod<String?>('getLaunchAction');
if (action != null) {
handler(action);
}
}
Future<void> initialize(QuickActionHandler handler) async =>
QuickActionsPlatform.instance.initialize(handler);

/// Sets the [ShortcutItem]s to become the app's quick actions.
Future<void> setShortcutItems(List<ShortcutItem> items) async {
final List<Map<String, String?>> itemsList =
items.map(_serializeItem).toList();
await channel.invokeMethod<void>('setShortcutItems', itemsList);
}
Future<void> setShortcutItems(List<ShortcutItem> items) async =>
QuickActionsPlatform.instance.setShortcutItems(items);

/// Removes all [ShortcutItem]s registered for the app.
Future<void> clearShortcutItems() =>
channel.invokeMethod<void>('clearShortcutItems');

Map<String, String?> _serializeItem(ShortcutItem item) {
return <String, String?>{
'type': item.type,
'localizedTitle': item.localizedTitle,
'icon': item.icon,
};
}
QuickActionsPlatform.instance.clearShortcutItems();
}
11 changes: 7 additions & 4 deletions packages/quick_actions/quick_actions/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: quick_actions
description: Flutter plugin for creating shortcuts on home screen, also known as
Quick Actions on iOS and App Shortcuts on Android.
homepage: https://github.com/flutter/plugins/tree/master/packages/quick_actions
version: 0.5.0+1
version: 0.6.0

flutter:
plugin:
Expand All @@ -17,15 +17,18 @@ dependencies:
flutter:
sdk: flutter
meta: ^1.3.0
quick_actions_platform_interface: ^1.0.0

dev_dependencies:
test: ^1.16.3
flutter_test:
sdk: flutter
integration_test:
sdk: flutter
pedantic: ^1.10.0
mockito: ^5.0.0-nullsafety.7
pedantic: ^1.11.0
plugin_platform_interface: ^2.0.0


environment:
sdk: ">=2.12.0-259.9.beta <3.0.0"
sdk: ">=2.12.0 <3.0.0"
flutter: ">=1.12.13+hotfix.5"
119 changes: 47 additions & 72 deletions packages/quick_actions/quick_actions/test/quick_actions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,90 +2,65 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'package:quick_actions/quick_actions.dart';
import 'package:quick_actions_platform_interface/platform_interface/quick_actions_platform.dart';
import 'package:quick_actions_platform_interface/quick_actions_platform_interface.dart';
import 'package:quick_actions_platform_interface/types/shortcut_item.dart';

void main() {
TestWidgetsFlutterBinding.ensureInitialized();
group('$QuickActions', () {
setUp(() {
QuickActionsPlatform.instance = MockQuickActionsPlatform();
});

late QuickActions quickActions;
final List<MethodCall> log = <MethodCall>[];
test('initialize() PlatformInterface', () async {
QuickActions quickActions = QuickActions();
QuickActionHandler handler = (type) {};

setUp(() {
quickActions = QuickActions();
quickActions.channel.setMockMethodCallHandler(
(MethodCall methodCall) async {
log.add(methodCall);
return 'non empty response';
},
);
});
await quickActions.initialize(handler);
verify(QuickActionsPlatform.instance.initialize(handler)).called(1);
});

test('setShortcutItems with demo data', () async {
const String type = 'type';
const String localizedTitle = 'localizedTitle';
const String icon = 'icon';
await quickActions.setShortcutItems(
const <ShortcutItem>[
ShortcutItem(type: type, localizedTitle: localizedTitle, icon: icon)
],
);
expect(
log,
<Matcher>[
isMethodCall(
'setShortcutItems',
arguments: <Map<String, String>>[
<String, String>{
'type': type,
'localizedTitle': localizedTitle,
'icon': icon,
}
],
),
],
);
log.clear();
});
test('setShortcutItems() PlatformInterface', () {
QuickActions quickActions = QuickActions();
QuickActionHandler handler = (type) {};
quickActions.initialize(handler);
quickActions.setShortcutItems([]);

test('clearShortcutItems', () {
quickActions.clearShortcutItems();
expect(
log,
<Matcher>[
isMethodCall('clearShortcutItems', arguments: null),
],
);
log.clear();
});
verify(QuickActionsPlatform.instance.initialize(handler)).called(1);
verify(QuickActionsPlatform.instance.setShortcutItems([])).called(1);
});

test('initialize', () async {
final Completer<bool> quickActionsHandler = Completer<bool>();
quickActions.initialize((_) => quickActionsHandler.complete(true));
expect(
log,
<Matcher>[
isMethodCall('getLaunchAction', arguments: null),
],
);
log.clear();
test('clearShortcutItems() PlatformInterface', () {
QuickActions quickActions = QuickActions();
QuickActionHandler handler = (type) {};

expect(quickActionsHandler.future, completion(isTrue));
quickActions.initialize(handler);
quickActions.clearShortcutItems();

verify(QuickActionsPlatform.instance.initialize(handler)).called(1);
verify(QuickActionsPlatform.instance.clearShortcutItems()).called(1);
});
});
}

test('Shortcut item can be constructed', () {
const String type = 'type';
const String localizedTitle = 'title';
const String icon = 'foo';
class MockQuickActionsPlatform extends Mock
with MockPlatformInterfaceMixin
implements QuickActionsPlatform {
@override
Future<void> clearShortcutItems() async =>
super.noSuchMethod(Invocation.method(#clearShortcutItems, []));

const ShortcutItem item =
ShortcutItem(type: type, localizedTitle: localizedTitle, icon: icon);
@override
Future<void> initialize(QuickActionHandler? handler) async =>
super.noSuchMethod(Invocation.method(#initialize, [handler]));

expect(item.type, type);
expect(item.localizedTitle, localizedTitle);
expect(item.icon, icon);
});
@override
Future<void> setShortcutItems(List<ShortcutItem>? items) async =>
super.noSuchMethod(Invocation.method(#setShortcutItems, [items]));
}

class MockQuickActions extends QuickActions {}