clickabletext 0.0.2

Flutter Android iOS web

Find Hashtag and Mention in Text and return List <TextSpan>.

clickabletext #

Find Hashtag and Mention seperately and both together. This package work for both android and IOS just use it as child of richtext.

Getting Started #

Screenshot #

Usage #

To use this package just add it to pubspec.yaml and like example use it.

Example

    dependencies:
        flutter:
            sdk: flutter
        clickabletext:

How to Use #

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Make Clickable Text',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Make Clickable Text'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  TextEditingController controller = TextEditingController();
  List<TextSpan> richText = List<TextSpan>();

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  void hashtagAction() {
    print("action clicked");
  }

  void mentionAction() {
    print("mention clicked");
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            TextField(
              controller: controller,
              style: TextStyle(),
              decoration: InputDecoration(
                hintText: 'Write some text with #, @ ',
              ),
            ),
            RaisedButton(
              child: Text("Put it Down"),
              onPressed: () {
                setState(() {
                  richText = FindSympol(controller.text)
                      .makeHashtagAndMention(hashtagAction, mentionAction);
                });
              },
            ),
            RichText(
              text: TextSpan(
                text: "",
                style: TextStyle(color: Colors.black),
                children: richText,
              ),
            )
          ],
        ),
      ),
    );
  }
}

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

3
likes
90
pub points
66%
popularity

Find Hashtag and Mention in Text and return List <TextSpan>.

Repository (GitLab)
View/report issues

Documentation

API reference

Uploader

amirmhmdi95@gmail.com

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on clickabletext