Created
January 27, 2024 19:31
-
-
Save lomza/0f8e0a0285ec26e1784ce23f1ac2de8c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math'; | |
const List<String> _flowers = [ | |
// 1st page | |
'Rose', | |
'Hydrangea', | |
'Sunflower', | |
'Daisy', | |
'Orchid', | |
'Lily', | |
'Chrysanthemum', | |
'Iris', | |
'Daffodil', | |
'Tulip', | |
// 2st page | |
'Azalea', | |
'Violet', | |
'Marigold', | |
'Peony', | |
'Begonia', | |
'Gardenia', | |
'Kale', | |
'Geranium', | |
'Hyacinth', | |
'Gladiolus', | |
// 3rd page | |
'Amaranthus', | |
'Zinnia', | |
'Anemone', | |
'Buttercup', | |
'Pansy', | |
'Aster', | |
'Larkspur', | |
'Petunia', | |
'Delphinium', | |
'Yarrow', | |
// 4th page | |
'Allium', | |
'Gerbera daisy', | |
'Astilbe', | |
'Snapdragon', | |
'Crocus', | |
'Dianthus', | |
'Cornflower', | |
'Celosia', | |
'Lisianthus', | |
'Gypsophila', | |
// 5th page | |
'Liatris', | |
'Agapanthus', | |
'Brunia', | |
]; | |
const int pageSize = 10; | |
class GetFlowersUseCase { | |
Future<List<String>> getFlowers({int page = 0}) async { | |
final start = page * pageSize; | |
final end = ++page * pageSize; | |
if (start >= _flowers.length) { | |
return _flowers; | |
} | |
// Simulate a paged API call response | |
final List<String> flowersList = _flowers.sublist(max(start, 0), min(end, _flowers.length)).toList(); | |
// Artificial delay to simulate an API call | |
await Future.delayed(const Duration(milliseconds: 2500)); | |
return flowersList; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment