Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yungzhu/rich_input
Rich input box, implement @someone and subject with color highlighting
https://github.com/yungzhu/rich_input
dart flutter input rich rich-text-editor textarea textfield textinput
Last synced: 3 days ago
JSON representation
Rich input box, implement @someone and subject with color highlighting
- Host: GitHub
- URL: https://github.com/yungzhu/rich_input
- Owner: yungzhu
- License: mit
- Created: 2020-07-02T06:20:10.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-06-16T07:19:24.000Z (over 1 year ago)
- Last Synced: 2023-08-20T23:00:53.960Z (about 1 year ago)
- Topics: dart, flutter, input, rich, rich-text-editor, textarea, textfield, textinput
- Language: Dart
- Homepage:
- Size: 113 KB
- Stars: 56
- Watchers: 3
- Forks: 20
- Open Issues: 5
-
Metadata Files:
- Readme: README-ZH.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# rich_input
这是一个高性能的富媒体输入框,通过原生的 textfield 扩展实现,具有较小的破坏性,同时具有较强的扩展性,实现了@某人,#话题,表情等功能,支持自定义高亮
文档语言: [English](README.md) | [中文简体](README-ZH.md)
## 特色功能
- 用较少的代码,尽量使用原生的 textfield 能力,减少破坏性及后续兼容性
- 支持@某人 #话题 插入表情等
- 支持自定义高亮效果,及自定义样式
- 支持使用退格键删除整个特殊文本块
- 支持特殊字符的处理
- 支持自定义 data 字段,增强富文本的能力![Demo](demo.png)
## 开始入门
核心代码
```dart
import 'package:rich_input/rich_input.dart';RichInputController controller = RichInputController(text: "Text");
const block = RichBlock(
text: "@somebody",
data: "@123456",
style: TextStyle(color: Colors.blue),
);
controller.insertBlock(block);// 获取自定义数据
print(controller.data);
// 获取文本
print(controller.text);// RichInput(controller: controller);
```详细示例
```dart
import 'package:flutter/material.dart';
import 'package:rich_input/rich_input.dart';void main() {
runApp(MyApp());
}class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: MyHomePage(),
);
}
}class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}class _MyHomePageState extends State {
RichInputController _controller;
FocusNode _focusNode;@override
void initState() {
_focusNode = FocusNode();
_controller = RichInputController(text: "Text");// Refresh text display, not required
_controller.addListener(() {
setState(() {});
});
super.initState();
}@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(15),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
RichInput(
focusNode: _focusNode,
controller: _controller,
),
Wrap(
spacing: 10,
children: [
RaisedButton(
onPressed: () {
_controller.insertText("Text");
},
child: const Text("Add Text"),
),
RaisedButton(
onPressed: () {
_controller.insertText("😁");
},
child: const Text("Add 😁"),
),
RaisedButton(
onPressed: () {
_controller.insertText("👍");
},
child: const Text("Add 👍"),
),
RaisedButton(
onPressed: () {
const block = RichBlock(
text: "@abc",
data: "@123456",
style: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.bold,
),
);
_controller.insertBlock(block);
},
child: const Text("Add @ "),
),
RaisedButton(
onPressed: () {
const block = RichBlock(
text: "#subject",
data: "#888999",
style: TextStyle(
color: Colors.red,
fontWeight: FontWeight.bold,
),
);
_controller.insertBlock(block);
},
child: const Text("Add #"),
),
RaisedButton(
onPressed: () {
_focusNode.unfocus();
},
child: const Text("unfocus"),
)
],
),
const SizedBox(height: 10),
Text("Text:${_controller.text}"),
const SizedBox(height: 10),
Text("Data:${_controller.data}"),
],
),
),
),
);
}
}
```> [详细示例,请查看](example/lib/main.dart)