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) {
  final bottomInset = MediaQuery.of(context).viewInsets.bottom; // 👈 detects keyboard
  final bool isKeyboardOpen = bottomInset > 0;

  return BlocProvider.value(
    value: authCubit,
    child: Scaffold(
      resizeToAvoidBottomInset: true,
      backgroundColor: Colors.white,
      body: SafeArea(
        child: Stack(
          children: [
            // Background
            Container(
              decoration: BoxDecoration(
                image: DecorationImage(
                  image: AssetImage("assets/images/login_bg.png",
                      package: 'azure_auth'),
                  fit: BoxFit.fitHeight,
                  alignment: Alignment.center,
                ),
              ),
            ),

            // Welcome text (only show if keyboard is NOT open)
            if (!isKeyboardOpen)
              Align(
                alignment: Alignment.topCenter,
                child: Container(
                  margin: const EdgeInsets.only(top: 180),
                  child: Column(
                    children: [
                      Text("Welcome to",
                          style: AppTextStyle.shrikhand_400),
                      Text(
                        "Vastu Shikhar",
                        style: AppTextStyle.appHeaderTextStyle.copyWith(
                          fontSize: 28,
                          color: Colors.white,
                        ),
                      ),
                    ],
                  ),
                ),
              ),

            // White login container
            AnimatedPositioned(
              duration: const Duration(milliseconds: 300),
              curve: Curves.easeInOut,
              top: isKeyboardOpen ? 0 : 280, // 👈 move to top when keyboard opens
              left: 0,
              right: 0,
              bottom: 0,
              child: Container(
                decoration: const BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(32),
                    topRight: Radius.circular(32),
                  ),
                ),
                child: SingleChildScrollView(
                  padding: EdgeInsets.only(
                    left: 18,
                    right: 18,
                    bottom: bottomInset + 20, // 👈 padding above keyboard
                    top: 18,
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Text(loginAsText,
                          style: AppTextStyle.roboto_slab_500),
                      const SizedBox(height: 28),

                      // Facebook Button
                      OutlinedButton.icon(
                        style: OutlinedButton.styleFrom(
                          minimumSize: const Size.fromHeight(54),
                          side: const BorderSide(
                              color: AppColor.color_light_grey),
                          backgroundColor: AppColor.color_FBF8F4,
                          shape: RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(8)),
                        ),
                        icon: const Icon(Icons.facebook,
                            color: Color(0xFF1877F2), size: 44),
                        label: Text(
                          "Sign in with Facebook",
                          style: AppTextStyle.roboto_slab_500
                              .copyWith(fontSize: 18),
                        ),
                        onPressed: () async {
                          await authCubit.loginFor(
                              fb_flowName, context);
                          onLoginSuccess();
                        },
                      ),
                      const SizedBox(height: 16),

                      // Google Button
                      OutlinedButton.icon(
                        style: OutlinedButton.styleFrom(
                          minimumSize: const Size.fromHeight(54),
                          side: const BorderSide(
                              color: AppColor.color_light_grey),
                          backgroundColor: AppColor.color_FBF8F4,
                          shape: RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(8)),
                        ),
                        icon: Image.asset(
                          Assets.iconsGLogo,
                          package: 'azure_auth',
                          width: 36,
                          height: 36,
                        ),
                        label: Text(
                          "    Sign in with Google",
                          style: AppTextStyle.roboto_slab_500
                              .copyWith(fontSize: 18),
                        ),
                        onPressed: () async {
                          await authCubit.loginFor(
                              google_flowName, context);
                          onLoginSuccess();
                        },
                      ),
                      const SizedBox(height: 20),

                      // Divider with OR
                      Row(
                        children: [
                          const Expanded(child: Divider(thickness: 1)),
                          Padding(
                            padding: const EdgeInsets.symmetric(
                                horizontal: 8.0),
                            child: Text(
                              "OR",
                              style: AppTextStyle.roboto_slab_500
                                  .copyWith(fontSize: 18),
                            ),
                          ),
                          const Expanded(child: Divider(thickness: 1)),
                        ],
                      ),
                      const SizedBox(height: 20),

                      // Email / Phone Field
                      Align(
                        alignment: Alignment.centerLeft,
                        child: Text(
                          "Email/Phone Number",
                          style: AppTextStyle.roboto_slab_500.copyWith(
                            fontSize: 18,
                            color: AppColor.color_404040,
                          ),
                        ),
                      ),
                      const SizedBox(height: 8),
                      AppTextFormField(
                        hintText: "Enter email or Phone number",
                        onChnaged: (value) {
                          id.value = value ?? "";
                        },
                        validator: phoneOrEmailValidation,
                      ),
                      const SizedBox(height: 30),

                      // Continue Button
                      Container(
                        width: double.infinity,
                        height: 55,
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(8),
                          gradient: const LinearGradient(
                            colors: [Color(0xFFE65C4F), Color(0xFFF9A825)],
                            begin: Alignment.centerLeft,
                            end: Alignment.centerRight,
                          ),
                        ),
                        child: ElevatedButton(
                          style: ElevatedButton.styleFrom(
                            backgroundColor: Colors.transparent,
                            shadowColor: Colors.transparent,
                          ),
                          onPressed: () async {
                            if (id.value.isNotEmpty) {
                              await authCubit.loginFor(
                                  email_phone_flowName, context,
                                  hint: id.value);
                              onLoginSuccess();
                            }
                          },
                          child: Text(
                            "Continue",
                            style: AppTextStyle.roboto_slab_500.copyWith(
                              fontSize: 18,
                              color: Colors.white,
                              fontWeight: FontWeight.w600,
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    ),
  );
}