Skip to content

Commit

Permalink
添加clipboard示例
Browse files Browse the repository at this point in the history
  • Loading branch information
0xZOne committed May 9, 2024
1 parent a4ffcee commit c686c16
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT
1. [ohos]问题已修复,统一使用回鸿蒙社区的git依赖
2. 更新FlutterBoost版本说明
3. 添加clipboard示例

# 4.5.6
1. [ohos]接管FlutterView绑定引擎的时机,解决Tab场景显示异常的问题,避免冗余的attach/detach
Expand Down
83 changes: 83 additions & 0 deletions example/lib/case/clipboard_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() => runApp(RunMyApp());

class RunMyApp extends StatelessWidget {
RunMyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(primarySwatch: Colors.green),
home: Scaffold(
appBar: AppBar(
title: const Text('Copy to Clipboard'),
),
body: ClipboardExample(),
),
);
}
}

class ClipboardExample extends StatelessWidget {
ClipboardExample({super.key});
// controller to retrieve the text
TextEditingController copy_controller = TextEditingController();
TextEditingController paste_controller = TextEditingController();
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(primarySwatch: Colors.green),
home: Scaffold(
appBar: AppBar(
title: const Text('Copy to Clipboard'),
),
body: Center(
child: Column(
children: [
TextField(
controller: copy_controller,
),
SizedBox(
height: 30,
),
ElevatedButton(
onPressed: () {
Clipboard.setData(
new ClipboardData(text: copy_controller.text))
.then((_) {
copy_controller.clear();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Copied to your clipboard !')));
});
},
child: const Text('Copy'),
),
SizedBox(
height: 50,
),
TextField(
controller: paste_controller,
decoration: const InputDecoration(
labelText: 'Pasted text will appear here',
border: OutlineInputBorder(),
),
),
ElevatedButton(
onPressed: () async {
Clipboard.getData('text/plain').then((value) {
paste_controller.text = value!.text!;
});
},
child: const Text('Paste'),
),
],
),
),
),
);
}
}
11 changes: 11 additions & 0 deletions example/lib/flutter_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,17 @@ class _FlutterIndexRouteState extends State<FlutterIndexRoute>
.then((value) =>
debugPrint('xlog, mediaquery, Return Value:$value')),
),
InkWell(
child: Container(
padding: const EdgeInsets.all(8.0),
margin: const EdgeInsets.all(8.0),
color: Colors.yellow,
child: const Text(
'Clipboard demo',
style: TextStyle(fontSize: 22.0, color: Colors.black),
)),
onTap: () => BoostNavigator.instance
.push("clipboard", withContainer: withContainer)),
InkWell(
child: Container(
padding: const EdgeInsets.all(8.0),
Expand Down
5 changes: 5 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter_boost/flutter_boost.dart';

import 'case/asset_image_route.dart';
import 'case/bottom_navigation_bar_demo.dart';
import 'case/clipboard_example.dart';
import 'case/counter_demo.dart';
import 'case/dual_screen.dart';
import 'case/flutter_rebuild_demo.dart';
Expand Down Expand Up @@ -390,6 +391,10 @@ class _MyAppState extends State<MyApp> {
settings: settings,
pageBuilder: (_, __, ___) => const SafeAreaPage());
},
'clipboard': (settings, uniqueId) {
return PageRouteBuilder<dynamic>(
settings: settings, pageBuilder: (_, __, ___) => ClipboardExample());
},

///使用 BoostCacheWidget包裹你的页面时,可以解决push pageA->pageB->pageC 过程中,pageA,pageB 会多次 rebuild 的问题
'flutterRebuildDemo': (settings, uniqueId) {
Expand Down

0 comments on commit c686c16

Please sign in to comment.