improve: Improves search performance with debouncing
Introduces a 500ms debounce delay for the search input on the reception search page. This prevents excessive API calls or data filtering on every keystroke, leading to a smoother user experience and reduced load. Also includes minor performance optimizations by adding const keywords and removing an unused import.
This commit is contained in:
parent
0b4e5042cc
commit
099334942a
@ -1,8 +1,8 @@
|
||||
import 'dart:async';
|
||||
import 'package:e_scan/backend/objectbox/entities/stock_picking/stock_picking_record_entity.dart';
|
||||
import 'package:e_scan/components/components.dart';
|
||||
import 'package:e_scan/pages/operation/reception/reception_search_page_model.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:e_scan/components/main_appbar_component.dart';
|
||||
import 'package:e_scan/themes/app_theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@ -15,6 +15,23 @@ class ReceptionSearchPage extends ConsumerStatefulWidget {
|
||||
}
|
||||
|
||||
class _ReceptionSearchPageState extends ConsumerState<ReceptionSearchPage> {
|
||||
Timer? _debounce;
|
||||
|
||||
void _onSearchChanged(String value) {
|
||||
_debounce?.cancel();
|
||||
_debounce = Timer(const Duration(milliseconds: 500), () {
|
||||
ref
|
||||
.read(receptionSearchPageModelProvider.notifier)
|
||||
.allByName(name: value);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_debounce?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final state = ref.watch(receptionSearchPageModelProvider);
|
||||
@ -41,18 +58,14 @@ class _ReceptionSearchPageState extends ConsumerState<ReceptionSearchPage> {
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
),
|
||||
onChanged: (value) {
|
||||
ref
|
||||
.read(receptionSearchPageModelProvider.notifier)
|
||||
.allByName(name: value);
|
||||
},
|
||||
onChanged: _onSearchChanged,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: state.isLoading
|
||||
? Center(child: LoadingProgressComponent())
|
||||
? const Center(child: LoadingProgressComponent())
|
||||
: receptions.isEmpty
|
||||
? Center(child: Text('Aucun résultat trouvé'))
|
||||
? const Center(child: Text('Aucun résultat trouvé'))
|
||||
: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: receptions
|
||||
|
Loading…
x
Reference in New Issue
Block a user