diff --git a/lib/components/basket_item_card.dart b/lib/components/basket_item_card.dart index 7756bf4..3fd4076 100644 --- a/lib/components/basket_item_card.dart +++ b/lib/components/basket_item_card.dart @@ -36,7 +36,7 @@ class BasketItemCard extends StatelessWidget { ), child: GestureDetector( onTap: () { - Navigator.of(context).pushReplacement( + Navigator.of(context).push( CustomPageRoute(builder: (context) => DetailPage(id: id))); }, child: Card( diff --git a/lib/pages/main.dart b/lib/pages/main.dart index b2d99d7..f48d288 100644 --- a/lib/pages/main.dart +++ b/lib/pages/main.dart @@ -69,6 +69,8 @@ class _MainPageState extends State { List filteredData = []; List items = []; int cartLength = 0; + int itemViewCount = 0; + bool isLoading = false; @override void initState() { @@ -81,6 +83,7 @@ class _MainPageState extends State { getItems(context).then((value) => setState(() { filteredData = value; items = value; + itemViewCount = min(5, value.length); })); } @@ -92,8 +95,14 @@ class _MainPageState extends State { } void _onLoad() async { - await Future.delayed(const Duration(milliseconds: 1000)); - debugPrint('aye'); + setState(() { + isLoading = true; + }); + await Future.delayed(const Duration(seconds: 1)); + setState(() { + itemViewCount = min(filteredData.length, itemViewCount + 5); + isLoading = false; + }); } void _onSearch() { @@ -101,6 +110,7 @@ class _MainPageState extends State { filteredData = items .where((element) => (element.title).contains(searchText)) .toList(); + itemViewCount = filteredData.length; }); } @@ -190,13 +200,16 @@ class _MainPageState extends State { Expanded( child: LazyLoadScrollView( onEndOfPage: _onLoad, - child: Stack( + isLoading: isLoading, + child: ListView( children: [ items.isEmpty ? const Center(child: CircularProgressIndicator()) : filteredData.isEmpty ? const Center(child: Text('Ничего не найдено')) : GridView.builder( + physics: const AlwaysScrollableScrollPhysics(), + shrinkWrap: true, gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: min( @@ -204,7 +217,7 @@ class _MainPageState extends State { .toInt(), 8), ), - itemCount: filteredData.length, + itemCount: itemViewCount, itemBuilder: (context, index) { final product = filteredData[index]; return ProductCard( @@ -225,6 +238,34 @@ class _MainPageState extends State { ); }, ), + 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(), ], ), ), diff --git a/lib/tools/items.dart b/lib/tools/items.dart index 5918df6..7b86bbc 100644 --- a/lib/tools/items.dart +++ b/lib/tools/items.dart @@ -32,7 +32,6 @@ Future> getItems(BuildContext context) async { return []; } -//FIXME: Сделать, чтоб работало Future> getItemsByIds( BuildContext context, List ids) async { final token = context.read().token;