Fix: Lazy loader on web and its indicator
This commit is contained in:
@@ -36,7 +36,7 @@ class BasketItemCard extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.of(context).pushReplacement(
|
Navigator.of(context).push(
|
||||||
CustomPageRoute(builder: (context) => DetailPage(id: id)));
|
CustomPageRoute(builder: (context) => DetailPage(id: id)));
|
||||||
},
|
},
|
||||||
child: Card(
|
child: Card(
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ class _MainPageState extends State<MainPage> {
|
|||||||
List<GymItem> filteredData = [];
|
List<GymItem> filteredData = [];
|
||||||
List<GymItem> items = [];
|
List<GymItem> items = [];
|
||||||
int cartLength = 0;
|
int cartLength = 0;
|
||||||
|
int itemViewCount = 0;
|
||||||
|
bool isLoading = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -81,6 +83,7 @@ class _MainPageState extends State<MainPage> {
|
|||||||
getItems(context).then((value) => setState(() {
|
getItems(context).then((value) => setState(() {
|
||||||
filteredData = value;
|
filteredData = value;
|
||||||
items = value;
|
items = value;
|
||||||
|
itemViewCount = min(5, value.length);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,8 +95,14 @@ class _MainPageState extends State<MainPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _onLoad() async {
|
void _onLoad() async {
|
||||||
await Future.delayed(const Duration(milliseconds: 1000));
|
setState(() {
|
||||||
debugPrint('aye');
|
isLoading = true;
|
||||||
|
});
|
||||||
|
await Future.delayed(const Duration(seconds: 1));
|
||||||
|
setState(() {
|
||||||
|
itemViewCount = min(filteredData.length, itemViewCount + 5);
|
||||||
|
isLoading = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onSearch() {
|
void _onSearch() {
|
||||||
@@ -101,6 +110,7 @@ class _MainPageState extends State<MainPage> {
|
|||||||
filteredData = items
|
filteredData = items
|
||||||
.where((element) => (element.title).contains(searchText))
|
.where((element) => (element.title).contains(searchText))
|
||||||
.toList();
|
.toList();
|
||||||
|
itemViewCount = filteredData.length;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,13 +200,16 @@ class _MainPageState extends State<MainPage> {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: LazyLoadScrollView(
|
child: LazyLoadScrollView(
|
||||||
onEndOfPage: _onLoad,
|
onEndOfPage: _onLoad,
|
||||||
child: Stack(
|
isLoading: isLoading,
|
||||||
|
child: ListView(
|
||||||
children: [
|
children: [
|
||||||
items.isEmpty
|
items.isEmpty
|
||||||
? const Center(child: CircularProgressIndicator())
|
? const Center(child: CircularProgressIndicator())
|
||||||
: filteredData.isEmpty
|
: filteredData.isEmpty
|
||||||
? const Center(child: Text('Ничего не найдено'))
|
? const Center(child: Text('Ничего не найдено'))
|
||||||
: GridView.builder(
|
: GridView.builder(
|
||||||
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
|
shrinkWrap: true,
|
||||||
gridDelegate:
|
gridDelegate:
|
||||||
SliverGridDelegateWithFixedCrossAxisCount(
|
SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
crossAxisCount: min(
|
crossAxisCount: min(
|
||||||
@@ -204,7 +217,7 @@ class _MainPageState extends State<MainPage> {
|
|||||||
.toInt(),
|
.toInt(),
|
||||||
8),
|
8),
|
||||||
),
|
),
|
||||||
itemCount: filteredData.length,
|
itemCount: itemViewCount,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final product = filteredData[index];
|
final product = filteredData[index];
|
||||||
return ProductCard(
|
return ProductCard(
|
||||||
@@ -225,6 +238,34 @@ class _MainPageState extends State<MainPage> {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
itemViewCount > 0
|
||||||
|
? Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||||
|
child: Center(
|
||||||
|
child: itemViewCount < filteredData.length
|
||||||
|
? !isLoading
|
||||||
|
? ElevatedButton(
|
||||||
|
onPressed: _onLoad,
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor:
|
||||||
|
Theme.of(context).primaryColor,
|
||||||
|
shape: const RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.all(
|
||||||
|
Radius.circular(50)),
|
||||||
|
),
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
),
|
||||||
|
child: const Text('Загрузить ещё'),
|
||||||
|
)
|
||||||
|
: const CircularProgressIndicator()
|
||||||
|
: const Text(
|
||||||
|
'Конец списка',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 10, color: Color(0x88000000)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: const SizedBox.shrink(),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ Future<List<GymItem>> getItems(BuildContext context) async {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
//FIXME: Сделать, чтоб работало
|
|
||||||
Future<List<GymItem>> getItemsByIds(
|
Future<List<GymItem>> getItemsByIds(
|
||||||
BuildContext context, List<String> ids) async {
|
BuildContext context, List<String> ids) async {
|
||||||
final token = context.read<GymLinkProvider>().token;
|
final token = context.read<GymLinkProvider>().token;
|
||||||
|
|||||||
Reference in New Issue
Block a user