typing_after_action 0.0.6
typing_after_action: ^0.0.6 copied to clipboard
A lightweight debounce helper for Flutter TextFields — run an action after the user stops typing for a configurable delay.
import 'package:flutter/material.dart';
import 'package:typing_after_action/typing_after_action.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'typing_after_action example',
home: const SearchPage(),
);
}
}
class SearchPage extends StatefulWidget {
const SearchPage({super.key});
@override
State<SearchPage> createState() => _SearchPageState();
}
class _SearchPageState extends State<SearchPage> {
// Waits 500ms after the user stops typing before running the action.
final TypingAfterAction _typingAfterAction =
TypingAfterAction(milliseconds: 500);
String _result = '';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('typing_after_action example')),
body: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextField(
decoration: const InputDecoration(labelText: 'Search'),
onChanged: (value) {
_typingAfterAction.run(() {
setState(() {
_result = 'Searching for "$value"...';
});
});
},
),
const SizedBox(height: 16),
Text(_result),
],
),
),
);
}
}