build method

  1. @override
Widget build(
  1. BuildContext context
)
override

Describes the part of the user interface represented by this widget.

The framework calls this method when this widget is inserted into the tree in a given BuildContext and when the dependencies of this widget change (e.g., an InheritedWidget referenced by this widget changes). This method can potentially be called in every frame and should not have any side effects beyond building a widget.

The framework replaces the subtree below this widget with the widget returned by this method, either by updating the existing subtree or by removing the subtree and inflating a new subtree, depending on whether the widget returned by this method can update the root of the existing subtree, as determined by calling Widget.canUpdate.

Typically implementations return a newly created constellation of widgets that are configured with information from this widget's constructor and from the given BuildContext.

The given BuildContext contains information about the location in the tree at which this widget is being built. For example, the context provides the set of inherited widgets for this location in the tree. A given widget might be built with multiple different BuildContext arguments over time if the widget is moved around the tree or if the widget is inserted into the tree in multiple places at once.

The implementation of this method must only depend on:

If a widget's build method is to depend on anything else, use a StatefulWidget instead.

See also:

  • StatelessWidget, which contains the discussion on performance considerations.

Implementation

@override
Widget build(BuildContext context) {
  useEffect(() {
    context.read<MainBloc>().add(MainEvent.init(initConfig));
    return null;
  }, []);
  return Scaffold(
    appBar: AppBar(
      title: const Text('Saving Cycle'),
      centerTitle: true,
      leadingWidth: 100.w,
    ),
    body: SingleChildScrollView(
      physics: const BouncingScrollPhysics(),
      child: BlocBuilder<MainBloc, MainState>(
        builder: (context, state) => Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              color: AppColors.primary,
              padding: EdgeInsets.all(AppSpacing.horizontalSpacing / 2),
              child: const Stack(
                children: [
                  Positioned(
                    left: 30,
                    child: Icon(
                      Icons.chevron_left,
                      color: Colors.white,
                    ),
                  ),
                  Center(
                    child: Text(
                      'Group Savings',
                      style: TextStyle(
                        color: Colors.white,
                      ),
                    ),
                  ),
                ],
              ),
            ),
            AppSpacing.verticalSpaceLarge,
            Padding(
              padding: EdgeInsets.symmetric(
                  horizontal: AppSpacing.horizontalSpacing),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  WalletCard(
                    value: state.initConfig.walletBalance?.toDouble() ?? 0,
                    currency: state.initConfig.primaryFiatCurrency,
                    balanceVisible: state.walletBalanceVisible,
                  ),
                  AppSpacing.verticalSpaceSmall,
                  Row(
                    children: [
                      Container(
                        decoration: BoxDecoration(
                          shape: BoxShape.circle,
                          color: AppColors.primary.withValues(alpha: .1),
                        ),
                        padding: EdgeInsets.all(4.r),
                        child: Icon(
                          Icons.add,
                          color: AppColors.primary,
                          size: 12.sp,
                        ),
                      ),
                      AppSpacing.horizontalSpaceSmall,
                      const Text(
                        'Start Group Saving',
                        style: TextStyle(
                          fontWeight: FontWeight.bold,
                        ),
                      )
                    ],
                  ),
                  AppSpacing.verticalSpaceSmall,
                  Text(
                    'Select any of the savings options to begin your contribution with others',
                    style: context.textTheme.bodySmall,
                  ),
                  AppSpacing.verticalSpaceMedium,
                  Padding(
                    padding: EdgeInsets.symmetric(
                        horizontal: AppSpacing.horizontalSpacing),
                    child: ContainerButton(
                      icon: 'open_group',
                      title: 'Create Open Group',
                      subtitle: 'This clearly implies that\nanyone can join',
                      onTap: () {
                        state.initConfig.eventConfig?.onTap
                            ?.call(TapEvent.createClosedSavingGroup);
                      },
                    ),
                  ),
                  AppSpacing.verticalSpaceMedium,
                  Padding(
                    padding: EdgeInsets.symmetric(
                        horizontal: AppSpacing.horizontalSpacing),
                    child: ContainerButton(
                      icon: 'closed_group',
                      title: 'Create Closed Group',
                      subtitle:
                          'This implies that\nyou can only join by invite',
                      onTap: () {
                        state.initConfig.eventConfig?.onTap
                            ?.call(TapEvent.createClosedSavingGroup);
                      },
                    ),
                  ),
                  AppSpacing.verticalSpaceLarge,
                  const Text(
                    'Other Saving Groups',
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  AppSpacing.verticalSpaceSmall,
                  SizedBox(
                    height: .65.sh,
                    child: RawScrollbar(
                      scrollbarOrientation: ScrollbarOrientation.top,
                      thickness: 4.r,
                      radius: Radius.circular(4.r),
                      thumbColor: AppColors.primary,
                      child: ListView(
                        scrollDirection: Axis.horizontal,
                        padding: EdgeInsets.only(
                            top: AppSpacing.horizontalSpacing / 2),
                        children: const [
                          SavingGroup(),
                          SavingGroup(),
                          SavingGroup(),
                          SavingGroup(),
                        ],
                      ),
                    ),
                  ),
                  AppSpacing.verticalSpaceMedium,
                  const Text(
                    'Group History',
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  DefaultTabController(
                    length: 2,
                    child: SizedBox(
                      height: .9.sh,
                      child: Column(
                        children: [
                          const TabBar(
                            labelColor: AppColors.textColor,
                            unselectedLabelColor: Colors.grey,
                            indicatorColor: AppColors.primary,
                            tabs: [
                              Tab(text: 'Ongoing'),
                              Tab(text: 'Completed'),
                            ],
                          ),
                          Expanded(
                            child: TabBarView(
                              children: [
                                Padding(
                                  padding: EdgeInsets.only(
                                      top: AppSpacing.horizontalSpacing),
                                  child: ScrollablePad(
                                    child: Padding(
                                      padding: EdgeInsets.symmetric(
                                          horizontal:
                                              AppSpacing.horizontalSpacing),
                                      child: Column(
                                        crossAxisAlignment:
                                            CrossAxisAlignment.start,
                                        children: [
                                          AppSpacing.verticalSpaceSmall,
                                          const Text('Active Groups'),
                                          AppSpacing.verticalSpaceSmall,
                                          Text(
                                            'These are the list of active groups you created',
                                            style: context.textTheme.bodySmall
                                                ?.copyWith(
                                              color: const Color(0xFF6E6C6C),
                                            ),
                                          ),
                                          AppSpacing.verticalSpaceSmall,
                                          const Text('My groups (2)'),
                                          AppSpacing.verticalSpaceSmall,
                                          const SavingGroup(
                                            completed: true,
                                          ),
                                          const SavingGroup(
                                            completed: true,
                                          ),
                                          AppSpacing.verticalSpaceSmall,
                                        ],
                                      ),
                                    ),
                                  ),
                                ),
                                Padding(
                                  padding: EdgeInsets.only(
                                      top: AppSpacing.horizontalSpacing),
                                  child: ScrollablePad(
                                    child: Padding(
                                      padding: EdgeInsets.symmetric(
                                          horizontal:
                                              AppSpacing.horizontalSpacing),
                                      child: Column(
                                        crossAxisAlignment:
                                            CrossAxisAlignment.start,
                                        children: [
                                          AppSpacing.verticalSpaceSmall,
                                          const Text('Previous Groups'),
                                          AppSpacing.verticalSpaceSmall,
                                          Text(
                                            'These are the list of active groups you created',
                                            style: context.textTheme.bodySmall
                                                ?.copyWith(
                                              color: const Color(0xFF6E6C6C),
                                            ),
                                          ),
                                          AppSpacing.verticalSpaceSmall,
                                          const Text(
                                              'My Previous Groups (2)'),
                                          AppSpacing.verticalSpaceSmall,
                                          const SavingGroup(
                                            completed: true,
                                          ),
                                          const SavingGroup(
                                            completed: true,
                                          ),
                                          AppSpacing.verticalSpaceSmall,
                                        ],
                                      ),
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    ),
    drawer: Container(),
  );
}