categoryRails
unknown
dart
3 years ago
7.9 kB
5
Indexable
import 'package:base_architecture/core/enums/following_type_enum.dart'; import 'package:base_architecture/core/extensions/widget_extensions.dart'; import 'package:base_architecture/core/shared_widgets/ac_list_item.dart'; import 'package:base_architecture/data_layer/models/api_models/books_models/book_model.dart'; import 'package:base_architecture/data_layer/models/api_models/categories_model.dart'; import 'package:base_architecture/presentation/notifiers/categories_notifier/categories_notifier.dart'; import 'package:base_architecture/presentation/pages/following_page/pages_widgets/following_details_page.dart'; import 'package:base_architecture/presentation/pages/more_category_page/more_category_page.dart'; import 'package:base_architecture/presentation/notifiers/theme_notifier.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; class CategoryRails extends StatelessWidget { const CategoryRails({ Key? key, required this.category, required this.categoryType, required this.categoryId, required this.moreBooks, required this.title, required this.railIndex, required this.sub_category, required this.sub_categoryId, }) : super(key: key); final List<CategoriesItem> category; final String? categoryType; final int categoryId; final List<Book> moreBooks; final String title; final int railIndex; final bool sub_category; final int? sub_categoryId; @override Widget build(BuildContext context) { Size mediaQuery = MediaQuery.of(context).size; ThemeNotifier themeNotifier = Provider.of<ThemeNotifier>( context, listen: true, ); return Column( children: [ Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Semantics( container: true, child: Text( title, style: themeNotifier.getTheme().textTheme.headline2!.copyWith( fontWeight: FontWeight.w500, color: themeNotifier.getTheme().hoverColor, fontSize: 20, ), ), ), Consumer<CategoriesNotifier>( builder: ( BuildContext context, CategoriesNotifier notifier, Widget? child, ) => InkWell( child: Semantics( container: true, button: true, child: Row( children: [ Text( 'More'.tr(), style: themeNotifier .getTheme() .textTheme .headline1! .copyWith( fontSize: 16, color: themeNotifier.getTheme().canvasColor, ), ), Icon( Icons.arrow_forward_ios, size: 10, color: themeNotifier.getTheme().canvasColor, ) ], ), ), highlightColor: Colors.transparent, splashColor: Colors.transparent, onTap: () async { if (sub_category) { print(categoryType); print(categoryId); print(railIndex); notifier.resetPageIndex(); notifier.categories.clear(); if (notifier.selections.type == 'category') { /// [sub_categoryId] if value is null mean all categories tap if (sub_categoryId != null) { await Navigator.of(context).push( MaterialPageRoute( builder: (BuildContext context) => MoreCategoryPage( categoryName: title, moreBooks: moreBooks, ), ), ); } else { DefaultTabController.of(context)! .animateTo(railIndex + 1); await notifier.setCategoriesTabIndex(railIndex + 1); notifier.selections.type = categoryType; notifier.selections.id = categoryId; await notifier.getAllCategories(notifier.selections); } } } else { if (notifier.selections.type == 'authors' || notifier.selections.type == 'readers' || notifier.selections.type == 'translators' || notifier.selections.type == 'publishers') { print('To contributer page'); notifier.selections.type = categoryType; notifier.selections.id = categoryId; print(categoryId); await notifier.getAllCategories(notifier.selections); print(notifier.contributor?.id ?? 'mm'); // await Navigator.of(context).push( // MaterialPageRoute( // builder: (BuildContext context) => // FollowingDetailsPage( // types: [FollowingTypeEnum.author], // ), // ), // ); } else { await Navigator.of(context).push( MaterialPageRoute( builder: (BuildContext context) => MoreCategoryPage( categoryName: title, moreBooks: moreBooks, ), ), ); } } }, ), ) ], ).padding( padding: const EdgeInsets.symmetric( horizontal: 20, vertical: 20, ), ), SizedBox( height: mediaQuery.height * 0.245, width: mediaQuery.width, child: ListView.builder( shrinkWrap: true, scrollDirection: Axis.horizontal, itemCount: category[railIndex].mainCategoryBooks!.length, itemBuilder: (BuildContext context, int indexPath) { return Container( margin: EdgeInsetsDirectional.only( start: indexPath == 0 ? 10 : 0, end: indexPath == category.length - 1 ? 10 : 0, ), child: InkWell( splashColor: Colors.transparent, highlightColor: Colors.transparent, child: ACListBookItem( book: category[railIndex].mainCategoryBooks![indexPath], ), onTap: () { // Navigator.of( // context, // ).push( // MaterialPageRoute( // builder: (BuildContext context) => BookDetailsPage( // props: BookInfoProps( // bookInfo: book, // ), // ), // ), // ); }, ), ); }, ), ), ], ); } }
Editor is loading...