flutter_spanned_controller 0.8.0+1 copy "flutter_spanned_controller: ^0.8.0+1" to clipboard
flutter_spanned_controller: ^0.8.0+1 copied to clipboard

discontinuedreplaced by: boustro

TextEditingController implementation that allows for rich text styling in Flutter.

example/lib/main.dart

// ignore_for_file: diagnostic_describe_all_properties, use_key_in_widget_constructors, public_member_api_docs
import 'package:flutter/material.dart';
import 'package:flutter_spanned_controller/flutter_spanned_controller.dart';

void main() {
  runApp(MaterialApp(
    title: 'flutter_spanned_controller',
    theme: ThemeData(primarySwatch: Colors.blue),
    home: MyHomePage(),
  ));
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

/// A simple attribute that makes the spanned text bold.
class BoldAttribute extends TextAttribute {
  /// Determine whether text typed before/after the start/end
  /// of the span is included in the span.
  @override
  SpanExpandRules get expandRules => SpanExpandRules(
        ExpandRule.inclusive,
        ExpandRule.inclusive,
      );

  @override
  TextAttributeValue resolve(BuildContext context) {
    return const TextAttributeValue(
      style: TextStyle(fontWeight: FontWeight.bold),
    );
  }
}

class _MyHomePageState extends State<MyHomePage> {
  final String quote = 'Pack my box with five dozen liquor jugs';
  late final SpannedTextEditingController controller =
      SpannedTextEditingController(
    text: '"$quote" is the better panagram.',
    spans: SpanList([AttributeSpan(BoldAttribute(), 1, quote.length + 1)]),
  );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('flutter_spanned_controller'),
      ),
      body: Center(
        // We pass the controller so it can work its magic and apply the text
        // span.
        child: Padding(
          padding: const EdgeInsets.all(8),
          child: TextField(controller: controller),
        ),
      ),
    );
  }
}
1
likes
110
pub points
0%
popularity

Publisher

verified publisherjjagg.dev

TextEditingController implementation that allows for rich text styling in Flutter.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

built_collection, characters, collection, equatable, flutter, meta

More

Packages that depend on flutter_spanned_controller