-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
100 additions
and
0 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
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,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'), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
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
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