import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      home: MyWidget(),
    ),
  );
}

class MyWidget extends StatefulWidget {
  const MyWidget({Key? key}) : super(key: key);

  @override
  State<MyWidget> createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyWidget> {
  String selectedTxt = '';
  String sampleTxt =
      '日本におけるFlutterでのアプリ開発が広く利用され、アプリ開発の効率が向上することを願って、日本語によるFlutterの情報を配信していきます。';

  @override
  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

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.