text_span_field 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 45

text_span_field #

pub package

Flutter自定义文本样式输入框,可以让你在TextField中显示不同样式的文本,例如 #话题# @用户 效果

Getting Started #

Flutter #

text_span_field: 1.0.0

Android 端集成 #

无需额外配置,已内部打入混淆配置

IOS #

无需额外配置

效果图 #

使用 #

TextSpanField(
            controller: TextEditingController(
              text: "这是一条测试信息,你们看他的颜色",
            ),
            rangeStyles: [
              RangeStyle(
                range: TextRange(start: 0, end: 1),
                style: TextStyle(color: Color(0xFF5BA2FF)),
              ),
              RangeStyle(
                range: TextRange(start: 3, end: 4),
                style: TextStyle(color: Color(0xFF9C7BFF)),
              ),
            ],
          ),

0.0.1 #

  • TODO: Describe initial release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:text_span_field/text_span_field.dart';
import 'package:text_span_field/range_style.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  /// 输入的文本内容如
  String text = "";

  /// 话题正则
  RegExp topicReg = new RegExp(r"#([^#]{1,})#");

  /// 用户提醒(@开头,以空格、冒号、斜杠/ 结束,不以@结束)
  RegExp accountRemindReg = new RegExp(r"@([^\s|\/|:|@]+)");

  @override
  void initState() {
    super.initState();
  }

  /// 获得文本输入框样式
  List<RangeStyle> getTextFieldStyle() {
    List<RangeStyle> result = [];

    // 匹配话题
    for (Match m in topicReg.allMatches(text)) {
      result.add(
        RangeStyle(
          range: TextRange(start: m.start, end: m.end),
          style: TextStyle(color: Color(0xFF9C7BFF)),
        ),
      );
    }

    // 匹配@
    for (Match m in accountRemindReg.allMatches(text)) {
      result.add(
        RangeStyle(
          range: TextRange(start: m.start, end: m.end),
          style: TextStyle(color: Color(0xFF5BA2FF)),
        ),
      );
    }
    return result.length == 0 ? null : result;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: TextSpanField(
            maxLines: null,
            onChanged: (value) => this.setState(() => text = value),
            decoration: InputDecoration(
              contentPadding: EdgeInsets.all(20),
              hintText: '分享你的点滴,记录这一刻...',
            ),
            rangeStyles: this.getTextFieldStyle(),
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  text_span_field: ^1.0.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:text_span_field/text_span_field.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
22
Health:
Code health derived from static analysis. [more]
46
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
45
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:text_span_field/text_span_field.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:text_span_field/text_span_field.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:text_span_field/text_span_field.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:text_span_field/text_span_field.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • text_span_field that is a package requiring null.

Health issues and suggestions

Fix lib/text_span_field.dart. (-53.90 points)

Analysis of lib/text_span_field.dart reported 15 warnings, 1 hint, including:

line 59 col 7: Missing case clause for 'linux'.

line 59 col 7: Missing case clause for 'macOS'.

line 59 col 7: Missing case clause for 'windows'.

line 82 col 7: Missing case clause for 'linux'.

line 82 col 7: Missing case clause for 'macOS'.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.1
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test