Giter Site home page Giter Site logo

mixaza / flutter_text_selection_controls_fixed Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yousseflasheen/flutter_text_selection_controls

0.0 0.0 0.0 1.95 MB

Create a custom text selection controls on top of the current copy, cut, paste and select all options to use them in your SelectableText or TextField widgets.

License: BSD 3-Clause "New" or "Revised" License

Objective-C 0.17% Kotlin 0.55% Dart 77.96% Swift 5.09% HTML 16.24%

flutter_text_selection_controls_fixed's Introduction

text_selection_controls

This package allows you to create custom text selection controls and use them in the SelectableText widget or in the TextForm or TextFormField widgets. You can style the texts and the icons to match the theme of your app.

Screenshots

Installation

In your flutter project add the dependency:

dependencies:
    ...
    text_selection_controls: ^[lataets_version]

Import package:

import 'package:text_selection_controls/text_selection_controls.dart';

Usage By Example

On SelectableText Widget
SelectableText(
 ...,
 selectionControls: FlutterSelectionControls(
  toolBarItems: <ToolBarItem>[]
 ),
...
)
On TextField Widget
TextFormField(
  selectionControls: FlutterSelectionControls(
    toolBarItems: <ToolBarItem>[]
  ),
...
)

The Tool Bar Item Class

This class takes two arguments: A widget which will be shown on the text selection tool bar and a callback function which will be called when the widget on the text selection tool bar is tapped or pressed.

class ToolBarItem {
  ToolBarItem({required this.item, this.onItemPressed, this.itemControl})
      : assert(
            onItemPressed == null ? itemControl != null : itemControl == null);
...
}

The tool bar item class also gives an option to choose between the handled callbacks actions namely: Select all, copy, cut and paste controls using the itemControl: ... argument, or to create your own callback methods using the onItemPressed: ... argument. Please not that you can only use one argument only when responding to callbacks.

An application example of itemControl being used
import 'package:text_selection_controls/text_selection_controls.dart';
import 'package:flutter/material.dart';


class FlutterControls extends StatelessWidget {
  const FlutterControls({ Key? key }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SelectableText(
      'This is an example of selectable text with Select All, Copy, Cut and Paste controls',
      selectionControls: FlutterSelectionControls(toolBarItems: [
        ToolBarItem(item: Text('Select All'), itemControl: ToolBarItemControl.selectAll),
        ToolBarItem(item: Icon(Icons.copy), itemControl: ToolBarItemControl.copy),
        ToolBarItem(item: Icon(Icons.cut), itemControl: ToolBarItemControl.cut),
        ToolBarItem(item: Icon(Icons.paste), itemControl: ToolBarItemControl.paste),

      ]),
    );
  }
}
An application example of onItemPressed being used
import 'package:text_selection_controls/text_selection_controls.dart';
import 'package:flutter/material.dart';


class CustomControls extends StatelessWidget {
  const CustomControls({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SelectableText(
      'This is an example of selectable text with a custom control.',
      selectionControls: FlutterSelectionControls(toolBarItems: [
        ToolBarItem(
            item: Icon(Icons.bookmark),
            onItemPressed: (String highlightedText, int startIndex, int endIndex) {
              print('Highlighted Text: $highlightedText');
              //TODO 
            })
      ]),
    );
  }
}

Windows, Linux and MacOS platforms + Web

The text_selection_controls: package is deisgned for android and iOS applications but also note that it is still safe to use with these platforms even though the text selection tool bar does not show when a text is highlighted.

flutter_text_selection_controls_fixed's People

Contributors

yousseflasheen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.