flutter_selectext 0.1.1

flutter_selectext #

Selectable text widget and able to set custom selection control.

image

Getting Started #

Add dependencies #

on pubspec.yaml

dependencies:
  flutter_selectext: ^0.1.1

Import library #

import 'package:flutter_selectext/flutter_selectext.dart';

Usage #

SelectableText #

  • use string

     SelectableText('your string');
    
  • use textspan

     SelectableText.rich(textspan);
    

    SelectableText default only can copy.

    you can custom controls and could refer to MarkText widget.

MarkText #

  • use string

      List<TextSelection> markList = List();
    
      void handlerMark(TextSelection selection) {
        setState(() {
          markList.add(selection);
        });
      }
    
      MarkText('your string',
        handlerMark: handlerMark,
        markColor: Colors.deepOrange,
        markList: markList);
    
  • use textspan

      List<TextSelection> markList = List();
    
      void handlerMark(TextSelection selection) {
        setState(() {
          markList.add(selection);
        });
      }
    
      MarkText(textspan,
        handlerMark: handlerMark,
        markColor: Colors.deepOrange,
        markList: markList);
    

[0.1.1] - 2019/04/28

  • try to fix error for dart pub.

[0.1.0] - 2019/04/28

  • add demo image

[0.0.4] - 2019/04/28

  • try to fix error for dart pub.

[0.0.3] - 2019/04/28

  • add flutter for environment on pubspec.yaml

[0.0.2] - 2019/04/28

  • do flutter format and delete unused class.

[0.0.1] - 2019/04/28

  • publish.

example/example.dart

import 'package:flutter/material.dart';
import 'package:flutter_selectext/flutter_selectext.dart';

void main() {
  runApp(new DemoApp());
}

class DemoApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Demo',
      theme: ThemeData(
        primarySwatch: Colors.grey,
      ),
      home: const SelectableTextDemo(),
    );
  }
}

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

  @override
  _SelectableTextDemoState createState() => _SelectableTextDemoState();
}

class _SelectableTextDemoState extends State<SelectableTextDemo> {
  List<TextSelection> markList = List();

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Selectable Text Demo'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            MarkText.rich(
              TextSpan(children: [
                TextSpan(
                    style: TextStyle(
                        color: Colors.amber,
                        fontSize: 30,
                        wordSpacing: 3,
                        shadows: [
                          Shadow(
                              color: Colors.black,
                              offset: Offset(6, 3),
                              blurRadius: 10)
                        ]),
                    text: 'This has mark option'),
                TextSpan(
                    style: TextStyle(
                      color: Colors.deepPurple,
                    ),
                    text: ' test test test!!'),
              ]),
              handlerMark: (TextSelection selection) {
                setState(() {
                  markList.add(selection);
                });
              },
              markColor: Colors.deepOrange,
              markList: markList,
            ),
            SelectableText.rich(
              TextSpan(
                children: [
                  TextSpan(
                      style: TextStyle(
                        color: Colors.amber,
                        fontSize: 30,
                        wordSpacing: 3,
                        shadows: [
                          Shadow(
                              color: Colors.black,
                              offset: Offset(6, 3),
                              blurRadius: 10),
                        ],
                      ),
                      text: 'You have pushed the'),
                  TextSpan(
                      style: TextStyle(
                        color: Colors.blueAccent,
                      ),
                      text: 'button this many times:'),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_selectext: ^0.1.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_selectext/flutter_selectext.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
69
Health:
Code health derived from static analysis. [more]
10
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
54
Learn more about scoring.

We analyzed this package on Aug 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.4

Platforms

Detected platforms:

Low code quality prevents platform classification.

Health issues and suggestions

Fix lib/src/selectable_text.dart. (-76.27 points)

Analysis of lib/src/selectable_text.dart failed with 5 errors:

line 90 col 29: Undefined class 'Gestures.GestureLongPressDragStartDetails'.

line 115 col 7: Undefined class 'Gestures.GestureLongPressDragUpdateDetails'.

line 131 col 32: Undefined class 'Gestures.GestureLongPressDragUpDetails'.

line 246 col 9: The named parameter 'onSingleLongTapDragUpdate' isn't defined.

line 247 col 9: The named parameter 'onSingleLongTapUp' isn't defined.

Fix lib/src/selectext_editable_text.dart. (-57.81 points)

Analysis of lib/src/selectext_editable_text.dart failed with 3 errors:

line 454 col 7: Missing concrete implementations of getter TextSelectionDelegate.copyEnabled, getter TextSelectionDelegate.cutEnabled, getter TextSelectionDelegate.pasteEnabled and getter TextSelectionDelegate.selectAllEnabled.

line 801 col 22: The method 'ancestorsOf' isn't defined for the class 'FocusScope'.

line 1112 col 28: The method 'reparentIfNeeded' isn't defined for the class 'FocusScopeNode'.

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

Low code quality prevents platform classification.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test