forked from qi-shun-wang/rich_clipboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding fallback implementation for unsupported platforms
- Loading branch information
Showing
5 changed files
with
37 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
// All functionality is implemented via a MethodChannel in Swift. This file is | ||
// here to stop Flutter from breaking. | ||
// Re-export the default method channel implementation so flutter code gen can | ||
// find it. | ||
export 'package:rich_clipboard_platform_interface/rich_clipboard_platform_interface.dart' | ||
show MethodChannelRichClipboard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
rich_clipboard_platform_interface/lib/rich_clipboard_platform_interface.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
rich_clipboard_platform_interface/lib/src/fallback_rich_clipboard.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'package:flutter/services.dart'; | ||
|
||
import '../rich_clipboard_platform_interface.dart'; | ||
|
||
/// A partial implementation of [RichClipboardPlatform] that provides | ||
/// functionality on unsupported platforms. | ||
/// | ||
/// This class uses Flutter's built-in [Clipboard] to provide plain text support | ||
/// and silently discards other content types | ||
class FallbackRichClipboard extends RichClipboardPlatform { | ||
@override | ||
Future<List<String>> getAvailableTypes() async => | ||
const [Clipboard.kTextPlain]; | ||
|
||
@override | ||
Future<RichClipboardData> getData() => Clipboard.getData(Clipboard.kTextPlain) | ||
.then((d) => RichClipboardData(text: d?.text)); | ||
|
||
@override | ||
Future<void> setData(RichClipboardData data) => Clipboard.setData(data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters