import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: MyWidget(),
),
);
}
class MyWidget extends StatefulWidget {
const MyWidget({Key? key}) : super(key: key);
State<MyWidget> createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
String selectedTxt = '';
String sampleTxt =
'日本におけるFlutterでのアプリ開発が広く利用され、アプリ開発の効率が向上することを願って、日本語によるFlutterの情報を配信していきます。';
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
selectedTxt,
style: const TextStyle(
color: Colors.blue,
),
),
const SizedBox(height: 16),
TextSelectionTheme(
data: const TextSelectionThemeData(
selectionColor: Colors.pink,
selectionHandleColor: Colors.amber,
),
child: SelectableText(
sampleTxt,
style: const TextStyle(
fontWeight: FontWeight.bold,
color: Colors.orange,
),
onSelectionChanged: (selection, cause) => setState(() {
selectedTxt = sampleTxt.substring(
selection.start,
selection.end,
);
}),
),
),
],
),
),
),
);
}
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.