Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
7.1 kB
1
Indexable
Never
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:numa/core/constants/Strings.dart';
import 'package:numa/core/shared_widgets/item_card_for_guest.dart';
import 'package:numa/core/shared_widgets/see_all_widget.dart';
import 'package:numa/data_layer/models/facts_articles_param.dart';
import 'package:numa/presentation/notifires/biometrics_notifier.dart';
import 'package:numa/presentation/notifires/guest_home_notifier.dart';
import 'package:numa/presentation/notifires/guest_notifier.dart';
import 'package:numa/presentation/notifires/my_set_notifier.dart';
import 'package:numa/presentation/notifires/theme_notifier.dart';
import 'package:numa/presentation/pages/guest_home_page/widgets/banner_widget.dart';
import 'package:numa/presentation/pages/guest_home_page/widgets/grid_widget.dart';
import 'package:numa/presentation/pages/guest_home_page/widgets/guest_app_bar.dart';
import 'package:numa/presentation/pages/guest_home_page/widgets/guest_header.dart';
import 'package:numa/core/shared_widgets/bottom_sheets/register_bottom_sheet.dart';
import 'package:numa/presentation/pages/guest_home_page/widgets/shimmer_guest_home.dart';
import 'package:numa/presentation/pages/home_page/widgets/home_blogs.dart';
import 'package:numa/presentation/pages/home_page/widgets/quest_home_collectors.dart';
import 'package:provider/provider.dart';

class GuestHomePage extends StatefulWidget {
  const GuestHomePage({super.key});

  @override
  State<GuestHomePage> createState() => _GuestHomePageState();
}

class _GuestHomePageState extends State<GuestHomePage> {
  late GuestAuthNotifier _guestAuthNotiifer;
  late GuestHomeNotifier _guestNotifier;
  late MySetNotifier _mySetNotifier;
  late BiometricsNotifier _biometricsNotifier;

  @override
  void initState() {
    inInit();
    super.initState();
  }

  late ScrollController scrollController;

  Future<void> inInit() async {
    scrollController = ScrollController();
    _guestNotifier = Provider.of<GuestHomeNotifier>(context, listen: false);
    _mySetNotifier = Provider.of<MySetNotifier>(context, listen: false);
    _guestAuthNotiifer = Provider.of<GuestAuthNotifier>(context, listen: false);
    _biometricsNotifier =
        Provider.of<BiometricsNotifier>(context, listen: false);
    FactsArticleParam param2 =
        FactsArticleParam(filter: Filter(type: 'ARTICLE'));
    await _guestAuthNotiifer.executeGuestAuth().then((_) async {
      Future.wait([
        _guestNotifier.executeGuestGridCount(),
        _guestNotifier.executeGuestBanner(),
        _mySetNotifier.excecutRecommendedGuest(1, 4),
        _mySetNotifier.excecutMyCollectors(1, 10),
        _mySetNotifier.excecutBlogs(1, 4, param2)
      ]);
    });
    _biometricsNotifier.initBiometricsSupport();
  }

  @override
  Widget build(BuildContext context) {
    ThemeNotifier themeNotifier =
        Provider.of<ThemeNotifier>(context, listen: true);
    GuestHomeNotifier guestHomeNotifier =
        Provider.of<GuestHomeNotifier>(context);

    return WillPopScope(
      onWillPop: () async => false,
      child: Scaffold(
        backgroundColor: themeNotifier.getTheme().primaryColor,
        extendBodyBehindAppBar: false,
        body: NestedScrollView(
          //controller: scrollController,
          headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
            return [_guestAppBar(), _guestHeader()];
          },
          body: MediaQuery.removePadding(
            context: context,
            removeTop: true,
            child: Padding(
              padding: const EdgeInsets.only(top: 18),
              child: ListView(
                //controller: scrollController,
                children: [
                  if (!guestHomeNotifier.gridLoading) ...[
                    const GridWidget(),
                    _bannerWidget(),
                    _albumMostPopular(),
                    Padding(
                      padding: const EdgeInsets.fromLTRB(20, 0, 20, 10),
                      child: Consumer<MySetNotifier>(
                          builder: (context, notifier, _) {
                        return Column(
                          children: List.generate(
                              notifier.recommendedEntityGuest.data?.length ?? 0,
                              (indexPath) {
                            return ItemCardForGuest(
                              name: notifier.recommendedEntityGuest
                                      .data?[indexPath].skuNuma ??
                                  '',
                              standard: notifier.recommendedEntityGuest
                                      .data?[indexPath].skuStandard ??
                                  '',
                              image: notifier.recommendedEntityGuest
                                      .data?[indexPath].frontImage ??
                                  '',
                              isBuy: true,
                              withRotateImage: true,
                              onTap: () {
                                showModalBottomSheet(
                                    context: context,
                                    backgroundColor:
                                        Theme.of(context).primaryColor,
                                    shape: const RoundedRectangleBorder(
                                      borderRadius: BorderRadius.vertical(
                                        top: Radius.circular(23),
                                      ),
                                    ),
                                    builder: (_) =>
                                        const RegisterBottomSheet(desc: null));
                              },
                            );
                          }),
                        );
                      }),
                    ),
                    SeeAllWidget(title: Strings.seeAll.tr(), onTap: () {}),
                    _collectors(),
                    _blogs(),
                    const SizedBox(
                      height: 100,
                    )
                  ] else
                    GuestHomeShimmer()
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }

  GuestAppBar _guestAppBar() => const GuestAppBar();

  GuestHeader _guestHeader() => const GuestHeader();

  BannerWidget _bannerWidget() => const BannerWidget();

  Widget _albumMostPopular() => Padding(
        padding: const EdgeInsets.symmetric(horizontal: 26.0),
        child: Text(
          'Album Most Popular'.tr(),
          style: Theme.of(context)
              .textTheme
              .headlineMedium!
              .copyWith(fontWeight: FontWeight.w900),
        ),
      );

  Widget _collectors() => QuestHomeCollectors(
        containerHeight: 300,
        title: Strings.suggestedCollectores.toUpperCase().tr(),
      );

  Widget _blogs() => const Padding(
        padding: EdgeInsets.only(top: 30),
        child: HomeBlogs(),
      );
}