feature/pagination #42
@ -50,8 +50,8 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
final AuthService _authService = AuthService();
|
final AuthService _authService = AuthService();
|
||||||
late ScrollController _scrollController;
|
late ScrollController _scrollController;
|
||||||
int _fetchCount = 0;
|
int _fetchCount = 0;
|
||||||
bool _last = false;
|
|
||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
|
bool _lastData = false;
|
||||||
|
|
||||||
Future<List<Events>> postsFuture = getPosts();
|
Future<List<Events>> postsFuture = getPosts();
|
||||||
List<Events> filteredPosts = [];
|
List<Events> filteredPosts = [];
|
||||||
@ -149,9 +149,12 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _incrementFetchCount() {
|
void _incrementFetchCount() {
|
||||||
|
if (!_lastData) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_fetchCount++;
|
_fetchCount++;
|
||||||
});
|
});
|
||||||
|
_fetchData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _scrollListener() {
|
void _scrollListener() {
|
||||||
@ -159,7 +162,8 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
_scrollController.position.maxScrollExtent) {
|
_scrollController.position.maxScrollExtent) {
|
||||||
_incrementFetchCount();
|
_incrementFetchCount();
|
||||||
}
|
}
|
||||||
_fetchData();
|
|
||||||
|
// Scroll to top
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _fetchData() async {
|
Future<void> _fetchData() async {
|
||||||
@ -467,23 +471,15 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
print("results fetch : ${body}");
|
print("results fetch : ${body}");
|
||||||
print("fetch count : ${_fetchCount}");
|
print("fetch count : ${_fetchCount}");
|
||||||
// Update state after getting the response
|
// Update state after getting the response
|
||||||
setState(() {
|
|
||||||
if ((body.isNotEmpty) || (_fetchCount > 0)) {
|
|
||||||
if (body.isEmpty) {
|
if (body.isEmpty) {
|
||||||
_fetchCount--;
|
_lastData = true;
|
||||||
_last = true;
|
|
||||||
}
|
}
|
||||||
|
setState(() {
|
||||||
|
if (body.isNotEmpty) {
|
||||||
// If we have results, map them to Events
|
// If we have results, map them to Events
|
||||||
if (!_last) {
|
filteredPosts.addAll(body
|
||||||
filteredPosts.addAll(
|
|
||||||
body
|
|
||||||
.map((e) => Events.fromJson(e as Map<String, dynamic>))
|
.map((e) => Events.fromJson(e as Map<String, dynamic>))
|
||||||
.toList(),
|
.toList());
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// If no results, clear filteredPosts
|
|
||||||
filteredPosts.clear();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -623,7 +619,7 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
labelText: 'Search by item',
|
labelText: 'Search by item',
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
_fetchCount = 0;
|
_fetchCount = 0;
|
||||||
_last = false;
|
_lastData = false;
|
||||||
if (value.isNotEmpty) {
|
if (value.isNotEmpty) {
|
||||||
setState(() {
|
setState(() {
|
||||||
itemName = value;
|
itemName = value;
|
||||||
@ -642,7 +638,7 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
},
|
},
|
||||||
onClear: () {
|
onClear: () {
|
||||||
_fetchCount = 0;
|
_fetchCount = 0;
|
||||||
_last = false;
|
_lastData = false;
|
||||||
setState(() {
|
setState(() {
|
||||||
inputItem.clear();
|
inputItem.clear();
|
||||||
itemName = '';
|
itemName = '';
|
||||||
@ -655,7 +651,7 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
suggestions: suggestionsItem,
|
suggestions: suggestionsItem,
|
||||||
onSuggestionTap: (suggestion) async {
|
onSuggestionTap: (suggestion) async {
|
||||||
_fetchCount = 0;
|
_fetchCount = 0;
|
||||||
_last = false;
|
_lastData = false;
|
||||||
setState(() {
|
setState(() {
|
||||||
itemName = suggestion['name'];
|
itemName = suggestion['name'];
|
||||||
inputItem.text = itemName;
|
inputItem.text = itemName;
|
||||||
@ -672,7 +668,7 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
labelText: 'Search by tags',
|
labelText: 'Search by tags',
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
_fetchCount = 0;
|
_fetchCount = 0;
|
||||||
_last = false;
|
_lastData = false;
|
||||||
if (value.isNotEmpty) {
|
if (value.isNotEmpty) {
|
||||||
setState(() {
|
setState(() {
|
||||||
itemTags = value;
|
itemTags = value;
|
||||||
@ -691,6 +687,7 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
},
|
},
|
||||||
onClear: () {
|
onClear: () {
|
||||||
_fetchCount = 0;
|
_fetchCount = 0;
|
||||||
|
_lastData = false;
|
||||||
setState(() {
|
setState(() {
|
||||||
inputTags.clear();
|
inputTags.clear();
|
||||||
});
|
});
|
||||||
@ -699,7 +696,7 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
suggestions: suggestionsTags,
|
suggestions: suggestionsTags,
|
||||||
onSuggestionTap: (suggestion) async {
|
onSuggestionTap: (suggestion) async {
|
||||||
_fetchCount = 0;
|
_fetchCount = 0;
|
||||||
_last = false;
|
_lastData = false;
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
itemTags = suggestion['name'];
|
itemTags = suggestion['name'];
|
||||||
@ -725,7 +722,7 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
labelText: 'Search by geographical zone',
|
labelText: 'Search by geographical zone',
|
||||||
onChanged: (value) async {
|
onChanged: (value) async {
|
||||||
_fetchCount = 0;
|
_fetchCount = 0;
|
||||||
_last = false;
|
_lastData = false;
|
||||||
|
|
||||||
if (value.isNotEmpty) {
|
if (value.isNotEmpty) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -749,7 +746,7 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
},
|
},
|
||||||
onClear: () async {
|
onClear: () async {
|
||||||
_fetchCount = 0;
|
_fetchCount = 0;
|
||||||
_last = false;
|
_lastData = false;
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
prefs.remove("city_lat");
|
prefs.remove("city_lat");
|
||||||
prefs.remove("city_long");
|
prefs.remove("city_long");
|
||||||
@ -766,7 +763,7 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
suggestions: suggestionsGeo,
|
suggestions: suggestionsGeo,
|
||||||
onSuggestionTap: (suggestion) async {
|
onSuggestionTap: (suggestion) async {
|
||||||
_fetchCount = 0;
|
_fetchCount = 0;
|
||||||
_last = false;
|
_lastData = false;
|
||||||
|
|
||||||
final latitude = suggestion['geometry']['coordinates'][1];
|
final latitude = suggestion['geometry']['coordinates'][1];
|
||||||
final longitude = suggestion['geometry']['coordinates'][0];
|
final longitude = suggestion['geometry']['coordinates'][0];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user