highlight_mentions 0.0.2 copy "highlight_mentions: ^0.0.2" to clipboard
highlight_mentions: ^0.0.2 copied to clipboard

A Flutter package to highlight mentions in text fields and display widgets.

example/lib/main.dart

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HighlightTextScreen(),
    );
  }
}

class HighlightTextScreen extends StatefulWidget {
  const HighlightTextScreen({super.key});

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

class _HighlightTextScreenState extends State<HighlightTextScreen> {
  final String _currentUsername = 'john';
  late List<String> mentionableNames = ['alice', 'bob', 'sss'];
  late HighlightTextEditingController _controller;
  final FocusNode _focusNode = FocusNode();

  String text = '';

  @override
  void initState() {
    super.initState();
    _controller = HighlightTextEditingController(
      mentionableNames: mentionableNames,
      currentUsername: _currentUsername,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Highlight Mentions')),
      body: Padding(
        padding: const EdgeInsets.all(24.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            HighlightedText(
                input: text,
                mentionableNames: mentionableNames,
                currentUsername: _currentUsername),
            SizedBox(
              height: 20,
            ),
            // HighlightedTextField(
            //     controller: _controller,
            //     onChanged: (value) {
            //       setState(() {
            //         text = value;
            //       });
            //     }),
            SizedBox(
              height: 20,
            ),
            MentionableTextField(
              focusNode: _focusNode,
              currentUsername: _currentUsername,
              mentionableNames: mentionableNames,
              onMentionSelected: (mention) {
                print('Mention selected: $mention');
              },
              textFieldDecoration: InputDecoration(
                border: OutlineInputBorder(),
                hintText: 'Type @ to mention...',
              ),
              suggestionDecoration: BoxDecoration(
                color: Colors.white,
                boxShadow: [
                  BoxShadow(
                    color: Colors.grey.withOpacity(0.5),
                    blurRadius: 10,
                    offset: Offset(0, 3),
                  ),
                ],
              ),
              controller: _controller,
            ),
          ],
        ),
      ),
    );
  }
}
6
likes
0
points
15
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package to highlight mentions in text fields and display widgets.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on highlight_mentions

Packages that implement highlight_mentions