Skip to content

Empty targetMatches causes Bad state: No element #52

@khoadng

Description

@khoadng

We should handle this case gracefully

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

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

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

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

class RichTextExample extends StatelessWidget {
  RichTextExample({super.key});
  final controller = RichTextController(
    text: 'Type "highlight" or "Flutter" here!',
    targetMatches: [],
    onMatch: (matches) {
      print('Matched: $matches');
    },
  );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('RichTextController Example')),
      body: Center(
        child: TextField(
          controller: controller,
        ),
      ),
    );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions