update carton form and add recent search
This commit is contained in:
53
lib/pages/widgets/suggest_list.dart
Normal file
53
lib/pages/widgets/suggest_list.dart
Normal file
@@ -0,0 +1,53 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../helpers/theme.dart';
|
||||
|
||||
typedef OnTap = Function(String query);
|
||||
|
||||
class SuggestList extends StatefulWidget {
|
||||
final List<String>? recentSearchList;
|
||||
final String prefKey;
|
||||
final OnTap? onTap;
|
||||
const SuggestList(
|
||||
{Key? key, this.recentSearchList, this.onTap, required this.prefKey})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
_SuggestListState createState() => _SuggestListState();
|
||||
}
|
||||
|
||||
class _SuggestListState extends State<SuggestList> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView.builder(
|
||||
itemCount: widget.recentSearchList?.length,
|
||||
itemBuilder: (context, index) {
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.restore, color: labelColor),
|
||||
title: Text(
|
||||
widget.recentSearchList?[index] ?? '',
|
||||
style: const TextStyle(color: primaryColor),
|
||||
),
|
||||
onTap: () {
|
||||
if (widget.onTap != null) {
|
||||
widget.onTap!(widget.recentSearchList![index]);
|
||||
}
|
||||
},
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.close, color: labelColor),
|
||||
onPressed: () async {
|
||||
setState(() {
|
||||
widget.recentSearchList
|
||||
?.remove(widget.recentSearchList?[index]);
|
||||
});
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
prefs.setStringList(widget.prefKey, widget.recentSearchList!);
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user