BookInfoTab

 avatar
unknown
dart
3 years ago
27 kB
3
Indexable
import 'package:base_architecture/core/extensions/widget_extensions.dart';
import 'package:base_architecture/data_layer/models/api_models/Dto/categories_selections.dart';
import 'package:base_architecture/data_layer/models/api_models/book_details_model.dart';
import 'package:base_architecture/data_layer/models/api_models/categories_model.dart';
import 'package:base_architecture/presentation/notifiers/bottom_nav_bar_notifier.dart/bottom_nav_bar_notifier.dart';
import 'package:base_architecture/presentation/notifiers/categories_notifier/categories_notifier.dart';
import 'package:base_architecture/presentation/notifiers/theme_notifier.dart';
import 'package:base_architecture/presentation/pages/more_category_page/more_category_page.dart';
import 'package:base_architecture/presentation/pages/following_page/pages_widgets/integrated_following_details_page.dart';
import 'package:base_architecture/presentation/pages/more_category_page/tags_more_category_page.dart';
import 'package:base_architecture/presentation/pages/notifications/widgets/more_text_widget.dart';
import 'package:base_architecture/presentation/props/book_info_props.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class BookInfoTab extends StatelessWidget {
  const BookInfoTab({
    Key? key,
    required this.selectedIndex,
    required this.props,
  }) : super(key: key);

  final int selectedIndex;
  final BookInfoProps props;

  @override
  Widget build(BuildContext context) {
    Size mediaQuery = MediaQuery.of(context).size;
    final ThemeNotifier themeNotifier = Provider.of<ThemeNotifier>(
      context,
      listen: true,
    );
    final BottomNavBarNotifier bottomNavNotifier =
        Provider.of<BottomNavBarNotifier>(
      context,
      listen: false,
    );
    final CategoriesNotifier categoriesNotifier =
        Provider.of<CategoriesNotifier>(
      context,
      listen: false,
    );
    final Data book = props.bookInfo.data!.first;
    bool language = context.locale == const Locale('en');
    int readerId = book.readers!.first.id!;
    int translatorId = book.translators!.first.id!;
    int publisherId = book.publishers!.first.id!;
    int categoryId = book.category!.id!;
    int subCategoryId = book.subcategory!.id!;
    int subSubCategoryId = book.subSubcategory!.id!;
    String categoryName = language
        ? book.category!.nameEn! +
            ' ' +
            book.subcategory!.nameEn! +
            ' ' +
            book.subSubcategory!.nameEn!
        : book.category!.nameAr! +
            ', ' +
            book.subcategory!.nameAr! +
            ', ' +
            book.subSubcategory!.nameAr!;
    String? bookTag =
        language ? book.tags!.first.nameEn! : book.tags!.first.nameAr!;
    String readerName = language
        ? book.readers!.first.fullNameDecode!.first.firstNameEn! +
            ' ' +
            book.readers!.first.fullNameDecode!.last.lastNameEn!
        : book.readers!.first.fullNameDecode!.first.firstNameAr! +
            ' ' +
            book.readers!.first.fullNameDecode!.last.lastNameAr!;
    String publisherName = language
        ? book.publishers!.first.fullNameDecode!.first.firstNameEn! +
            ' ' +
            book.publishers!.first.fullNameDecode!.last.lastNameEn!
        : book.publishers!.first.fullNameDecode!.first.firstNameAr! +
            ' ' +
            book.publishers!.first.fullNameDecode!.last.lastNameAr!;
    String translatorName = language
        ? book.translators!.first.fullNameDecode!.first.firstNameEn! +
            ' ' +
            book.translators!.first.fullNameDecode!.last.lastNameEn!
        : book.translators!.first.fullNameDecode!.first.firstNameAr! +
            ' ' +
            book.translators!.first.fullNameDecode!.last.lastNameAr!;
    return Visibility(
      child: Container(
        width: mediaQuery.width,
        padding: const EdgeInsets.only(top: 20),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Visibility(
              visible: !book.readers!.isEmpty,
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    child: Text(
                      'reader'.tr() + '  ',
                      style: themeNotifier
                          .getTheme()
                          .textTheme
                          .headline2!
                          .copyWith(
                            fontSize: 16,
                            color: Colors.grey,
                          ),
                    ),
                  ),
                  Expanded(
                    child: ListView.builder(
                      physics: const NeverScrollableScrollPhysics(),
                      shrinkWrap: true,
                      itemCount: book.readers!.length,
                      itemBuilder: (BuildContext context, int indexPath) =>
                          InkWell(
                        child: Text(
                          language
                              ? book.readers![indexPath].fullNameDecode!.first
                                      .firstNameEn! +
                                  ' ' +
                                  book.readers![indexPath].fullNameDecode!.last
                                      .lastNameEn! +
                                  ','
                              : book.readers![indexPath].fullNameDecode!.first
                                      .firstNameAr! +
                                  ' ' +
                                  book.readers![indexPath].fullNameDecode!.last
                                      .lastNameAr! +
                                  ',',
                          style: themeNotifier
                              .getTheme()
                              .textTheme
                              .bodyText1!
                              .copyWith(
                                fontSize: 16,
                                color: themeNotifier.getTheme().canvasColor,
                                decoration: TextDecoration.underline,
                                decorationThickness: 1,
                                decorationColor:
                                    themeNotifier.getTheme().canvasColor,
                              ),
                        ),
                        onTap: () async {
                          CategoriesSelections lastSelections =
                              CategoriesSelections(
                            type: categoriesNotifier.selections.type!,
                            id: categoriesNotifier.selections.id,
                            keyword: categoriesNotifier.selections.keyword,
                          );
                          await categoriesNotifier.setLastSelections(
                            lastSelections,
                          );
                          print(categoriesNotifier.lastSelectionType);
                          categoriesNotifier.selections.id =
                              book.readers![indexPath].id!;

                          categoriesNotifier.selections.type = 'readers';
                          categoriesNotifier.resetPageIndex();
                          categoriesNotifier.categories.clear();
                          await categoriesNotifier.getAllCategories(
                            categoriesNotifier.selections,
                          );

                          await Navigator.of(context).push(
                            MaterialPageRoute(
                              builder: (BuildContext context) =>
                                  IntegratedFollowingDetailsPage(
                                contributor: categoriesNotifier.contributor ??
                                    ContributorCategories(),
                                contributorBooks:
                                    categoriesNotifier.subcategoriesBooks,
                                backToContributor: false,
                              ),
                            ),
                          );
                        },
                      ),
                    ),
                  )
                ],
              ),
            ),
            Visibility(
              visible: !book.readers!.isEmpty,
              child: const Divider(
                color: Colors.grey,
              ).padding(padding: const EdgeInsets.symmetric(vertical: 3)),
            ),
            Visibility(
              visible: book.isbn != null,
              child: Row(
                children: <Widget>[
                  Text(
                    'International ISBN'.tr() + ' ',
                    style:
                        themeNotifier.getTheme().textTheme.headline2!.copyWith(
                              fontSize: 16,
                              color: Colors.grey,
                            ),
                  ),
                  Text(
                    book.isbn!,
                    overflow: TextOverflow.ellipsis,
                    style:
                        themeNotifier.getTheme().textTheme.headline2!.copyWith(
                              fontSize: 16,
                              color: Colors.grey,
                            ),
                  ),
                ],
              ),
            ),
            Visibility(
              visible: book.isbn != null,
              child: const Divider(
                color: Colors.grey,
              ).padding(padding: const EdgeInsets.symmetric(vertical: 3)),
            ),
            Visibility(
              visible: !book.translators!.isEmpty,
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    child: Text(
                      'translator'.tr() + '  ',
                      style: themeNotifier
                          .getTheme()
                          .textTheme
                          .headline2!
                          .copyWith(
                            fontSize: 16,
                            color: Colors.grey,
                          ),
                    ),
                  ),
                  Expanded(
                    child: ListView.builder(
                      shrinkWrap: true,
                      physics: const NeverScrollableScrollPhysics(),
                      itemCount: book.translators!.length,
                      itemBuilder: (BuildContext context, int indexPath) =>
                          InkWell(
                        child: Text(
                          language
                              ? book.translators![indexPath].fullNameDecode!
                                      .first.firstNameEn! +
                                  ' ' +
                                  book.translators![indexPath].fullNameDecode!
                                      .last.lastNameEn! +
                                  ','
                              : book.translators![indexPath].fullNameDecode!
                                      .first.firstNameAr! +
                                  ' ' +
                                  book.translators![indexPath].fullNameDecode!
                                      .last.lastNameAr! +
                                  ',',
                          style: themeNotifier
                              .getTheme()
                              .textTheme
                              .bodyText1!
                              .copyWith(
                                fontSize: 16,
                                color: themeNotifier.getTheme().canvasColor,
                                decoration: TextDecoration.underline,
                                decorationThickness: 1,
                                decorationColor:
                                    themeNotifier.getTheme().canvasColor,
                              ),
                        ),
                        onTap: () async {
                          CategoriesSelections lastSelections =
                              CategoriesSelections(
                            type: categoriesNotifier.selections.type!,
                            id: categoriesNotifier.selections.id,
                            keyword: categoriesNotifier.selections.keyword,
                          );
                          await categoriesNotifier.setLastSelections(
                            lastSelections,
                          );
                          categoriesNotifier.selections.id =
                              book.translators![indexPath].id!;
                          categoriesNotifier.selections.type = 'translators';
                          categoriesNotifier.resetPageIndex();
                          await categoriesNotifier.getAllCategories(
                            categoriesNotifier.selections,
                          );

                          await Navigator.of(context).push(
                            MaterialPageRoute(
                              builder: (BuildContext context) =>
                                  IntegratedFollowingDetailsPage(
                                contributor: categoriesNotifier.contributor ??
                                    ContributorCategories(),
                                contributorBooks:
                                    categoriesNotifier.subcategoriesBooks,
                                backToContributor: false,
                              ),
                            ),
                          );
                        },
                      ),
                    ),
                  )
                ],
              ),
            ),
            Visibility(
              visible: !book.translators!.isEmpty,
              child: const Divider(
                color: Colors.grey,
              ).padding(padding: const EdgeInsets.symmetric(vertical: 3)),
            ),
            Visibility(
              visible: !book.publishers!.isEmpty,
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    child: Text(
                      'publishing house'.tr() + '  ',
                      style: themeNotifier
                          .getTheme()
                          .textTheme
                          .headline2!
                          .copyWith(
                            fontSize: 16,
                            color: Colors.grey,
                          ),
                    ),
                  ),
                  Expanded(
                    child: ListView.builder(
                      shrinkWrap: true,
                      physics: const NeverScrollableScrollPhysics(),
                      itemCount: book.publishers!.length,
                      itemBuilder: (BuildContext context, int indexPath) =>
                          InkWell(
                        child: Text(
                          language
                              ? book.publishers![indexPath].fullNameDecode!
                                      .first.firstNameEn! +
                                  ' ' +
                                  book.publishers![indexPath].fullNameDecode!
                                      .last.lastNameEn! +
                                  ','
                              : book.publishers![indexPath].fullNameDecode!
                                      .first.firstNameAr! +
                                  ' ' +
                                  book.publishers![indexPath].fullNameDecode!
                                      .last.lastNameAr! +
                                  ',',
                          style: themeNotifier
                              .getTheme()
                              .textTheme
                              .bodyText1!
                              .copyWith(
                                fontSize: 16,
                                color: themeNotifier.getTheme().canvasColor,
                                decoration: TextDecoration.underline,
                                decorationThickness: 1,
                                decorationColor:
                                    themeNotifier.getTheme().canvasColor,
                              ),
                        ),
                        onTap: () async {
                          CategoriesSelections lastSelections =
                              CategoriesSelections(
                            type: categoriesNotifier.selections.type!,
                            id: categoriesNotifier.selections.id,
                            keyword: categoriesNotifier.selections.keyword,
                          );
                          await categoriesNotifier.setLastSelections(
                            lastSelections,
                          );
                          categoriesNotifier.selections.id =
                              book.publishers![indexPath].id;
                          categoriesNotifier.selections.type = 'publishers';
                          categoriesNotifier.resetPageIndex();
                          await categoriesNotifier.getAllCategories(
                            categoriesNotifier.selections,
                          );

                          await Navigator.of(context).push(
                            MaterialPageRoute(
                              builder: (BuildContext context) =>
                                  IntegratedFollowingDetailsPage(
                                contributor: categoriesNotifier.contributor ??
                                    ContributorCategories(),
                                contributorBooks:
                                    categoriesNotifier.subcategoriesBooks,
                                backToContributor: false,
                              ),
                            ),
                          );
                        },
                      ),
                    ),
                  )
                ],
              ),
            ),
            Visibility(
              visible: !book.publishers!.isEmpty,
              child: const Divider(
                color: Colors.grey,
              ).padding(padding: const EdgeInsets.symmetric(vertical: 3)),
            ),
            RichText(
              text: TextSpan(
                text: 'Year of Publication'.tr() + ' ',
                style: themeNotifier.getTheme().textTheme.headline2!.copyWith(
                      fontSize: 16,
                      color: Colors.grey,
                    ),
                children: <TextSpan>[
                  TextSpan(
                    text: book.publicationYear,
                    style:
                        themeNotifier.getTheme().textTheme.bodyText1!.copyWith(
                              fontSize: 16,
                              color: themeNotifier.getTheme().hoverColor,
                            ),
                  ),
                ],
              ),
              overflow: TextOverflow.ellipsis,
            ),
            const Divider(
              color: Colors.grey,
            ).padding(padding: const EdgeInsets.symmetric(vertical: 3)),
            InkWell(
              onTap: () async {
                print(subSubCategoryId);
                categoriesNotifier.selections.type = 'category';
                categoriesNotifier.selections.id = categoryId;
                categoriesNotifier.selections.sub_id = subCategoryId;
                categoriesNotifier.selections.sub_sub_id = subSubCategoryId;
                categoriesNotifier.categories.clear();
                categoriesNotifier.resetPageIndex();
                categoriesNotifier
                    .getAllCategories(
                      categoriesNotifier.selections,
                    )
                    .then((value) => categoriesNotifier.setMoreCategoryIndex(
                          categoriesNotifier.subCategoriesTab.indexWhere(
                            (MainCategoriesTabs element) =>
                                element.id == book.subSubcategory!.id,
                          ),
                        ));
                // "id":1,"sub_id":2,"sub_sub_id":15

                await Navigator.of(context).push(
                  MaterialPageRoute(
                    builder: (BuildContext context) => MoreCategoryPage(
                      categoryName: language
                          ? book.subSubcategory!.nameEn!
                          : book.subSubcategory!.nameAr!,
                      moreBooks: categoriesNotifier.subcategoriesBooks,
                    ),
                  ),
                );

                // id":19,"sub_id":21,"sub_sub_id":28
                // "id":19,"sub_id":null,"sub_sub_id":null
              },
              child: RichText(
                text: TextSpan(
                  text: 'book category'.tr() + ' ',
                  style: themeNotifier.getTheme().textTheme.headline2!.copyWith(
                        fontSize: 16,
                        color: Colors.grey,
                      ),
                  children: <TextSpan>[
                    TextSpan(
                      text: categoryName,
                      style: themeNotifier
                          .getTheme()
                          .textTheme
                          .bodyText1!
                          .copyWith(
                            fontSize: 16,
                            color: themeNotifier.getTheme().canvasColor,
                            decoration: TextDecoration.underline,
                            decorationThickness: 1,
                            decorationColor:
                                themeNotifier.getTheme().canvasColor,
                          ),
                    ),
                  ],
                ),
                overflow: TextOverflow.ellipsis,
              ),
            ),
            const Divider(
              color: Colors.grey,
            ).padding(padding: const EdgeInsets.symmetric(vertical: 3)),
            Visibility(
              visible: !book.tags!.isEmpty,
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    child: Text(
                      'Tags'.tr() + '  ',
                      style: themeNotifier
                          .getTheme()
                          .textTheme
                          .headline2!
                          .copyWith(
                            fontSize: 16,
                            color: Colors.grey,
                          ),
                    ),
                  ),
                  Expanded(
                    child: ListView.builder(
                      shrinkWrap: true,
                      physics: const NeverScrollableScrollPhysics(),
                      itemCount: book.tags!.length,
                      itemBuilder: (BuildContext context, int indexPath) =>
                          InkWell(
                        child: Text(
                          language
                              ? book.tags![indexPath].nameEn!
                              : book.tags![indexPath].nameAr!,
                          style: themeNotifier
                              .getTheme()
                              .textTheme
                              .bodyText1!
                              .copyWith(
                                fontSize: 16,
                                color: themeNotifier.getTheme().canvasColor,
                                decoration: TextDecoration.underline,
                                decorationThickness: 1,
                                decorationColor:
                                    themeNotifier.getTheme().canvasColor,
                              ),
                        ),
                        onTap: () async {
                          categoriesNotifier.selections.id =
                              book.tags![indexPath].id;
                          categoriesNotifier.selections.type = 'tag';
                          categoriesNotifier.resetPageIndex();
                          categoriesNotifier.categories.clear();
                          categoriesNotifier
                              .getAllCategories(categoriesNotifier.selections);
                          await Navigator.of(context).push(
                            MaterialPageRoute(
                              builder: (BuildContext context) =>
                                  TagsMoreCategoryPage(
                                categoryName: language
                                    ? book.tags![indexPath].nameEn!
                                    : book.tags![indexPath].nameAr!,
                                moreBooks:
                                    categoriesNotifier.subcategoriesBooks,
                              ),
                            ),
                          );
                        },
                      ),
                    ),
                  )
                ],
              ),
            ),
            Visibility(
              visible: !book.tags!.isEmpty,
              child: const Divider(
                color: Colors.grey,
              ).padding(padding: const EdgeInsets.symmetric(vertical: 3)),
            ),
            ListTile(
              contentPadding: const EdgeInsets.only(bottom: 10),
              title: Padding(
                padding: const EdgeInsets.only(bottom: 10.0),
                child: Text(
                  'About the book'.tr(),
                  style: themeNotifier.getTheme().textTheme.headline2!.copyWith(
                        height: 1.5,
                        color: Colors.grey,
                        fontSize: 16,
                      ),
                ),
              ),
              subtitle: MoreTextWidget(
                firstPart: 300,
                text: book.description!,
                textStyle:
                    themeNotifier.getTheme().textTheme.headline2!.copyWith(
                          height: 1.3,
                          color: themeNotifier.getTheme().hoverColor,
                          fontSize: 16,
                        ),
              ),
            )
          ],
        ),
      ),
      maintainState: true,
      visible: selectedIndex == 0,
    );
  }
}
Editor is loading...