搜尋套件、儲存庫與 APP 分類

GitHub 儲存庫yogi7y/smart-text-field

智慧型文字欄位

SmartTextField 是一個 TextInput,旨在從原始文字中無縫提取寶貴資訊,讓收集各種類型的資料更加輕鬆,且不會中斷使用者流程。

智慧型文字欄位 專案封面
星標
3
分支
1
最近推送(UTC)
2024年12月20日
專案狀態
未封存

原始 README

以下為英文專案原文快照,最新內容請造訪 GitHub。

SmartTextField - Capture information seamlessly with natural language input

SmartTextField is a TextInput that aims to extract valuable information seamlessly from raw text, making it easier to collect various types of data without breaking the user flow. 🚀

SmartTextField Demo

🌟 Introduction

In traditional user interfaces, users often need to navigate through multiple input fields to provide different types of information, which can disrupt the flow and lead to a suboptimal user experience. SmartTextField addresses this issue by allowing users to enter all the required information in a single text field, using a natural language format.

💡 Use Case

For instance, in a task management app, if a user wants to provide the due date, project, and priority for a task, they can simply type all the information in the text field as a normal, readable text in one flow. Instead of having separate input fields for each piece of information, the user can enter something like: "Buy groceries tomorrow @personal #p2"

SmartTextField will then parse and extract the relevant information from the user's input text:

  • Due date: tomorrow
  • Project: personal
  • Priority: p2

🛠️ Implementation

SmartTextField achieves this functionality by taking a set of patterns and possible values from the client. The client implements a Tokenizer component, which has the following properties:

  1. pattern: A regular expression used to match patterns in the user's input text and invoke a list of possible values. 🔍
  2. values: A list of values that will be shown to the user if a pattern is matched. Fuzzy matching can be used to find the closest value to the user's input. Value can be any type and must implement Tokenable.
@immutable
class Project implements Tokenable {
  const Project({required this.name});

  final String name;

  @override
  String get prefix => ProjectTokenizer.prefixId;

  @override
  String get stringValue => name;
}
  ProjectTokenizer({
    required super.values,
    super.prefix = prefixId,
  });

  static const prefixId = '@';
const _projects = <Project>[
  Project(name: 'Run a marathon'),
  Project(name: 'Learn to code'),
  Project(name: 'Write a book'),
  Project(name: 'House renovation'),
  Project(name: 'Travel to Japan'),
  Project(name: 'Learn to play the guitar'),
];

The client can define multiple Tokenizer instances, each with its own pattern & values, to handle different types of information (e.g., dates, projects, priorities, etc.) and pass it to the SmartTextFieldController.

final _controller = SmartTextFieldController(
  tokenizers: [
    ProjectTokenizer(values: _projects),
  ],
);

return SmartTextField(
  controller: _controller,
  textFormFieldBuilder: (context, controller) => TextFormField(
    controller: controller,
    decoration: const InputDecoration(
      hintText: 'Enter your task...',
    ),
  ),
  // Optional: Customize how suggestions appear
  suggestionItemBuilder: (context, suggestion) => ListTile(
    title: Text(suggestion),
    leading: const Icon(Icons.task),
  ),
);

⚠️ Important: Always use the controller provided by the textFieldBuilder function in your TextFormField. The builder receives the same controller instance that was passed to SmartTextField, ensuring proper synchronization.

Ensure that the root of your app is wrapped with SmartTextFieldOverlay to display the overlay of suggestions.

return SmartTextFieldOverlay(
  child: MaterialApp(
    title: 'Smart TextField',
      home: Builder(builder: (context) => const SmartTextFieldScreen()),
    ),
  );
📖 Reading Extracted Values

highlightedTokens stores a list of extracted values from the raw text. To listen for latest changes, attach a listener on initState. 👂

@override
void initState() {
  super.initState();
  _controller.highlightedTokens.addListener(_onHighlightedTokensChanged);
}

void _onHighlightedTokensChanged() {
  final _extractedTime = _controller.highlightedDateTime; /// Returns the extracted DateTime from the raw text.

  final highlightedTokens = _controller.highlightedTokens.value; /// Map of extracted tokens that can be looked up by their prefix.

  final _project = highlightedTokens[ProjectTokenizer.prefixId];
}

🚀 Benefits

  • Streamlined User Experience: Users can enter all the required information in a single, continuous flow, without the need to navigate between multiple input fields. 🏃‍♀️
  • Natural Language Input: Users can express information using natural language, making the input process more intuitive and user-friendly. 🗣️
  • Customizable Patterns and Values: Clients can define their own patterns and possible values based on their specific requirements, making SmartTextField highly flexible and adaptable. 🔧

Ready to take your app's user experience to the next level? Give SmartTextField a try! 🎉

Yogesh Parwani GitHub avatar
GitHub 作者

Yogesh Parwani ↗

Senior Software Engineer (SDE 3) • Flutter • Award-Winning Apps: Top 4 out of 12k+ startups Asia '21, Best startup IIT Bombay '21 ・Scaling Apps for 20M+ Users

CoinDCXMumbai官方網站 ↗
語言DartKotlin

分類

使用的依賴

依賴清單 6 項

  • collection^1.18.0
  • flutter{"sdk":"flutter"}
  • flutter_portal^1.1.4
  • meta^1.10.0
  • flutter_test開發依賴{"sdk":"flutter"}
  • lints_y開發依賴{"git":{"url":"https://github.com/Yogi-7y/Project-Y.git","path":"packages/lints_y","ref":"main"}}

如何選擇適合專案的儲存庫?

先依使用情境篩選,再比較專案活躍情況,最後到原始儲存庫確認使用要求。

  1. 透過儲存庫名稱、作者或描述搜尋,再依技術分類縮小範圍。
  2. 綜合星標、分支與最近推送比較專案;星標反映社群關注,不保證品質。
  3. 使用前在 GitHub 確認 README、授權條款與 Issues。

來源與維護

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗