From 2e2a36d6fa9264df2120b55d2769fffac5f25cde Mon Sep 17 00:00:00 2001 From: ume-kun1015 Date: Wed, 15 Jan 2025 14:14:51 +0900 Subject: [PATCH 1/2] fix: use selectable text --- lib/src/ui/components/animated_text.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/ui/components/animated_text.dart b/lib/src/ui/components/animated_text.dart index f2d4145..a232bfd 100644 --- a/lib/src/ui/components/animated_text.dart +++ b/lib/src/ui/components/animated_text.dart @@ -49,7 +49,7 @@ class AnimatedText extends HookWidget { position: offsetAnimation.value!, child: FadeTransition( opacity: opacityAnimation.value!, - child: Text(text), + child: SelectableText(text), ), ); } From a58b0d61ce1cd9e4826cf2bd2fbb78abd02dbd4b Mon Sep 17 00:00:00 2001 From: ume-kun1015 Date: Wed, 15 Jan 2025 14:45:03 +0900 Subject: [PATCH 2/2] feat: show snackbar when text gets copied --- lib/panache.dart | 91 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 28 deletions(-) diff --git a/lib/panache.dart b/lib/panache.dart index e029c14..9aac0c2 100644 --- a/lib/panache.dart +++ b/lib/panache.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:panache/src/model/lorem.dart'; import 'package:panache/src/ui/components/animated_text.dart'; @@ -11,38 +12,72 @@ class Panache extends HookWidget { Widget build(BuildContext context) { final generated = useState(Lorem().generate()); - return Padding( - padding: const EdgeInsets.all(16), - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - spacing: 16.0, - children: [ - SizedBox( - width: 280, - child: Sidebar(onNumsChanged: ({ - required paragraphs, - required sentences, - required words, - }) { - generated.value = Lorem().generate( - paragraphs: paragraphs, - sentences: sentences, - words: words, - ); - }), + return Stack( + children: [ + Padding( + padding: const EdgeInsets.all(16), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + spacing: 16.0, + children: [ + SizedBox( + width: 280, + child: Sidebar(onNumsChanged: ({ + required paragraphs, + required sentences, + required words, + }) { + generated.value = Lorem().generate( + paragraphs: paragraphs, + sentences: sentences, + words: words, + ); + }), + ), + VerticalDivider(thickness: 4, color: Colors.yellow), + Expanded( + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.start, + children: [AnimatedText(text: generated.value)], + ), + ), + ), + ], ), - VerticalDivider(thickness: 4, color: Colors.yellow), - Expanded( - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.start, - children: [AnimatedText(text: generated.value)], + ), + Positioned( + bottom: 16.0, + right: 16.0, + child: SizedBox( + width: 48, + height: 48, + child: IconButton( + style: IconButton.styleFrom( + foregroundColor: Colors.orange, + backgroundColor: Colors.yellow, ), + padding: EdgeInsets.all(0.0), + icon: const Icon(Icons.copy), + onPressed: () async { + final snackBar = SnackBar( + width: 360.0, + content: const Text("Copied Text!!"), + duration: const Duration(seconds: 2), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10), + ), + behavior: SnackBarBehavior.floating, + ); + ScaffoldMessenger.of(context).showSnackBar(snackBar); + + await Clipboard.setData(ClipboardData(text: generated.value)); + }, ), ), - ], - ), + ) + ], ); } }