Beginners Tutorial: How To Design UI In Flutter

Flutter, an open-source mobile SDK created by Google, is a tool that makes it easy to build UIs for iOS and Android apps. Flutter’s framework provides all the building blocks necessary to create UI widgets: views, navigation, and actions.

This article will discuss how to design UI in a flutter. It’s good if you are already familiar with Android & IOS UI implementation. It’s a mixture of both. The Login Page is a good example, so let’s begin.

Basically, before we know how to design UI in flutter, we need to analyze the requirements (what widgets we need to design the UI)

  • We need the Edit Text to enter the email id & password field.
  • And the second thing we need is one login button.

So, your code should look like this, using the BLoC pattern.

mobile_signin_screen.dart

import 'package:email_validator/email_validator.dart';

import 'package:flutter/cupertino.dart';

import 'package:flutter/material.dart';

import 'package:flutter/services.dart';

import 'package:flutter_bloc/flutter_bloc.dart';

import 'package:flutter_demo_app/Screen/ForgotPassScreen/view/forgot_pass_page.dart';

import 'package:flutter_demo_app/Screen/LoginScreen/cubit/signin_cubit.dart';

import 'package:flutter_demo_app/Screen/SignupScreen/view/signup_page.dart';

import 'package:flutter_demo_app/utils/form_button.dart';

import 'package:flutter_demo_app/utils/form_fields.dart';

import 'package:flutter_svg/svg.dart';

import 'package:font_awesome_flutter/font_awesome_flutter.dart';

import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';




class MobileSigninScreen extends StatelessWidget {

 MobileSigninScreen({Key key}) : super(key: key);

 final _scaffoldKey = GlobalKey<ScaffoldState>();

 final GlobalKey<FormState> _formKey = GlobalKey<FormState>();

 @override

 Widget build(BuildContext context) {

   return BlocBuilder<SigninCubit, SigninState>(

     builder: (context, state) {

       return WillPopScope(

           onWillPop: () async {

         SystemNavigator.pop();

       },

       child:

         Scaffold(

           key: _scaffoldKey,

           body: ModalProgressHUD(

             inAsyncCall: state.signUpSignStatus == Status.inprogress,

             child: SingleChildScrollView(

               child: Stack(children: [

                 Container(

                     margin: EdgeInsets.fromLTRB(20, 60, 20, 0),

                     alignment: Alignment.topLeft,

                     decoration: BoxDecoration(

                         // color: Colors.white,

                         ),

                     child: SingleChildScrollView(

                         padding: EdgeInsets.fromLTRB(10, 20, 10, 0),

                         child: Container(

                             // new line

                             child: Column(

                                 mainAxisAlignment: MainAxisAlignment.start,

                                 children: <Widget>[

                               _BuildHeader(),

                               Form(

                                   key: _formKey,

                                   child: Column(

                                     crossAxisAlignment:

                                         CrossAxisAlignment.center,

                                     mainAxisAlignment:

                                         MainAxisAlignment.center,

                                     children: <Widget>[

                                       _BuildEmailInput(),

                                       _BuildPasswordInput(),

                                     ],

                                   )),

                               Row(

                                   crossAxisAlignment: CrossAxisAlignment.end,

                                   mainAxisAlignment: MainAxisAlignment.end,

                                   children: <Widget>[

                                     _BuildForgotPasswordButton(),

                                   ]),

                               _BuildButton(_formKey),

                               _GoogleLoginButton(),

                               _BuildORText(),

                               _BuildSignUpButton(),

                             ]))))

               ]),

             ),

           )));

     },

   );

 }

}




class _BuildHeader extends StatelessWidget {

 const _BuildHeader({Key key}) : super(key: key);




 @override

 Widget build(BuildContext context) {

   return BlocBuilder<SigninCubit, SigninState>(builder: (context, state) {

     return Column(

       children: [

         SvgPicture.asset(

           "assets/icons/sign_in_account_label.svg",

         )

       ],

     );

   });

 }

}




class _BuildEmailInput extends StatelessWidget {

 const _BuildEmailInput({Key key}) : super(key: key);




 @override

 Widget build(BuildContext context) {

   return BlocBuilder<SigninCubit, SigninState>(

       buildWhen: (previous, current) => previous.email != current.email,

       builder: (context, state) {

         return Padding(

             padding: EdgeInsets.only(top: 60),

             child: TextFormField(

               autovalidateMode: AutovalidateMode.onUserInteraction,

               style: TextStyle(fontSize: 15),

               decoration: FormFields.getInputDecoration('Email Id'),

               autocorrect: false,

               validator: (value) {

                 if (value.isEmpty) {

                   return 'Please enter your email';

                 }

                 if (!EmailValidator.validate(value, true, true)) {

                   return 'Please enter a valid email address';

                 }

                 return null;

               },

               //email space allow validation - edited by Kiran Patil

               onChanged: (email) => context

                   .read<SigninCubit>()

                   .emailChanged(email.replaceAll(" ", "")),

             ));

       });

 }

}




class _BuildPasswordInput extends StatelessWidget {

 @override

 Widget build(BuildContext context) {

   return BlocBuilder<SigninCubit, SigninState>(

       buildWhen: (previous, current) => previous.password != current.password,

       builder: (context, state) {

         return Padding(

             padding: EdgeInsets.only(top: 15),

             child: TextFormField(

               autovalidateMode: AutovalidateMode.onUserInteraction,

               // focusNode: myFocusNode,

               obscureText: !state.showPassword,

               // controller: textController,

               style: TextStyle(fontSize: 15),




               decoration: InputDecoration(

                 contentPadding:

                     EdgeInsets.symmetric(vertical: 10, horizontal: 20),

                 labelText: "Password",

                 suffixIcon: GestureDetector(

                   onTap: () {

                     context.read<SigninCubit>().isShowPassword();

                   },

                   child: Padding(

                       padding: EdgeInsets.all(5),

                       child: !state.showPassword

                           ? SvgPicture.asset("assets/icons/btn_show.svg")

                           : Image.asset(

                               "assets/icons/hide_btn.png",

                               width: 55,

                               height: 25,

                             )),

                 ),

                 labelStyle: TextStyle(color: const Color(0xFF828282)),

                 focusedBorder: OutlineInputBorder(

                   // gapPadding: 20,

                   borderRadius: BorderRadius.circular(2),

                   borderSide: const BorderSide(

                     color: Colors.black,

                   ),

                 ),

                 enabledBorder: OutlineInputBorder(

                     borderRadius: BorderRadius.circular(1),

                     borderSide: BorderSide(color: const Color(0xFFE0E0E0))),

                 focusedErrorBorder: OutlineInputBorder(

                     borderRadius: BorderRadius.circular(1),

                     borderSide: BorderSide(color: Colors.red)),

                 border: OutlineInputBorder(

                     borderRadius: BorderRadius.circular(1),

                     borderSide: BorderSide(color: const Color(0xFFE0E0E0))),

                 // border: InputBorder(borderSide: BorderStyle.solid),

               ),

               validator: (value) {

                 if (value.isEmpty) {

                   return 'Please enter a password';

                 }

                 return null;

               },

               onChanged: (password) =>

                   context.read<SigninCubit>().passwordChanged(password),

             ));

       });

 }

}




class _BuildButton extends StatelessWidget {

 GlobalKey<FormState> formKey;




 _BuildButton(GlobalKey<FormState> this.formKey, {Key key}) : super(key: key);

 @override

 Widget build(BuildContext context) {

   return BlocBuilder<SigninCubit, SigninState>(builder: (context, state) {

     return Padding(

         padding: const EdgeInsets.fromLTRB(0, 30, 0, 10),

         child:

             // SizedBox.expand(child:

             SizedBox(

           width: double.maxFinite,

           child: ElevatedButton(

               style: FormButton.getButtonStyle(),

               onPressed: () {

                 if (formKey.currentState.validate()) {

                   context.read<SigninCubit>().logInWithCredentials();

                 }

               },

               child: FormButton.getButtonText("Sign In")),

         )

         // )

         );

   });

 }

}




class _BuildForgotPasswordButton extends StatelessWidget {

 const _BuildForgotPasswordButton({Key key}) : super(key: key);




 @override

 Widget build(BuildContext context) {

   return BlocBuilder<SigninCubit, SigninState>(builder: (context, state) {

     return InkWell(

         onTap: () => {

               Navigator.of(context).push(MaterialPageRoute(

                   builder: (context) => ForgotPass(),

                   settings: RouteSettings(name: "/forgot_password")))

             },

         child: Padding(

             padding: EdgeInsets.symmetric(vertical: 20, horizontal: 0),

             child: RichText(

                 textAlign: TextAlign.center,

                 text: const TextSpan(children: [

                   TextSpan(

                       text: 'Forgot Password?',

                       style:

                           TextStyle(color: Color(0xFF333333), fontSize: 14))

                 ]))));

   });

 }

}




class _BuildSignUpButton extends StatelessWidget {

 const _BuildSignUpButton({Key key}) : super(key: key);




 @override

 Widget build(BuildContext context) {

   return BlocBuilder<SigninCubit, SigninState>(builder: (context, state) {

     return Padding(

         padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),

         child: SizedBox(

           width: double.maxFinite,

           child: ElevatedButton(

               style: FormButton.getButtonStyle(),

               onPressed: () {

                 {

                   Navigator.of(context).push(MaterialPageRoute(

                       builder: (context) => SignUp(),

                       settings: RouteSettings(name: "/signup")));

                 }

               },

               child: FormButton.getButtonText("Register")),

         )

         // )

         );

   });

 }

}




class _GoogleLoginButton extends StatelessWidget {

 @override

 Widget build(BuildContext context) {

   final theme = Theme.of(context);

   return Container(

       width: double.maxFinite,

       child: ElevatedButton.icon(

         label: const Text(

           'SIGN IN WITH GOOGLE',

           style: TextStyle(color: Colors.white),

         ),

         style: ElevatedButton.styleFrom(

           shape: RoundedRectangleBorder(

             borderRadius: BorderRadius.circular(30),

           ),

           primary: theme.colorScheme.secondary,

         ),

         icon: const Icon(FontAwesomeIcons.google, color: Colors.white),

         onPressed: () => context.read<SigninCubit>().logInWithGoogle(),

       ));

 }

}




class _BuildORText extends StatelessWidget {

 const _BuildORText({Key key}) : super(key: key);




 @override

 Widget build(BuildContext context) {

   return BlocBuilder<SigninCubit, SigninState>(builder: (context, state) {

     return Row(

       crossAxisAlignment: CrossAxisAlignment.center,

       mainAxisAlignment: MainAxisAlignment.center,

       children: [

         Container(

           color: Color(0xFF707070),

           height: 1,

           width: 70,

         ),

         Padding(

             padding: EdgeInsets.symmetric(vertical: 20, horizontal: 5),

             child: Text(

               "OR",

               style: TextStyle(fontSize: 12, color: Color(0xFF707070)),

             )),

         Container(

           color: Color(0xFF707070),

           height: 1,

           width: 70,

         ),

       ],

     );

   });

 }

}

What I did is we needed to show the 2 text fields & a login button in the column, so we had to take one container and place all these 3 widgets in the column so it could be shown to us vertically. And as they have properties we can change the style & behavior as per our requirement.

Hire Flutter Developers at your Ease

If someone wants to show the widgets in the horizontal form, they can do that using the Row component. They can use try cross-axis alignment and main-axis alignment as well. As we need to save the state of our widgets we used Flutter BLoC.

So the output will probably be seen like this. For more in detail, you can refer  the guide to building layouts in Flutter.

coma

Conclusion

The Flutter UI design is not the same as android or iOS; you need to add UI manually and align them in your layout. But, it’s quite good as it uses material UI & is flexible with any device. So here we conclude the tutorial on how to design UI in flutter.

Kiran

Kiran is an android & flutter developer with around 3.5 + years of experience in developing mobile applications. She is self-motivated, a quick learner & result oriented. She likes to learn new technologies and grow with it. She is good at developing clean, reusable, and latest technologies oriented code with interactive apps.

Get in touch for a detailed discussion.

Hear From Our 100+ Customers
coma

Mindbowser helped us build an awesome iOS app to bring balance to people’s lives.

author
ADDIE WOOTTEN
CEO, SMILINGMIND
coma

We had very close go live timeline and MindBowser team got us live a month before.

author
Shaz Khan
CEO, BuyNow WorldWide
coma

They were a very responsive team! Extremely easy to communicate and work with!

author
Kristen M.
Founder & CEO, TotTech
coma

We’ve had very little-to-no hiccups at all—it’s been a really pleasurable experience.

author
Chacko Thomas
Co-Founder, TEAM8s
coma

Mindbowser is one of the reasons that our app is successful. These guys have been a great team.

author
Dave Dubier
Founder & CEO, MangoMirror
coma

Mindbowser was very helpful with explaining the development process and started quickly on the project.

author
Hieu Le
Executive Director of Product Development, Innovation Lab
coma

The greatest benefit we got from Mindbowser is the expertise. Their team has developed apps in all different industries with all types of social proofs.

author
Alex Gobel
Co-Founder, Vesica
coma

Mindbowser is professional, efficient and thorough. 

author
MacKenzie R
Consultant at XPRIZE
coma

Very committed, they create beautiful apps and are very benevolent. They have brilliant Ideas.

author
Laurie Mastrogiani
Founder, S.T.A.R.S of Wellness
coma

MindBowser was great; they listened to us a lot and helped us hone in on the actual idea of the app.” “They had put together fantastic wireframes for us.

author
Bennet Gillogly
Co-Founder, Flat Earth
coma

They're very tech-savvy, yet humble.

author
Uma Nidmarty
CEO, GS Advisorate, Inc.
coma

Ayush was responsive and paired me with the best team member possible, to complete my complex vision and project. Could not be happier.

author
Katie Taylor
Founder, Child Life On Call
coma

As a founder of a budding start-up, it has been a great experience working with Mindbower Inc under Ayush's leadership for our online digital platform design and development activity.

author
Radhika Kotwal
Founder of Courtyardly
coma

The team from Mindbowser stayed on task, asked the right questions, and completed the required tasks in a timely fashion! Strong work team!

author
Michael Wright
Chief Executive Officer, SDOH2Health LLC
coma

They are focused, patient and; they are innovative. Please give them a shot if you are looking for someone to partner with, you can go along with Mindbowser.

author
David Cain
CEO, thirty2give
coma

We are a small non-profit on a budget and they were able to deliver their work at our prescribed budgets. Their team always met their objectives and I'm very happy with the end result. Thank you, Mindbowser team!!

author
Bart Mendel
Founder, Mindworks
coma

Mindbowser was easy to work with and hit the ground running, immediately feeling like part of our team.

author
George Hodulik
CEO, Stealth Startup, Ex-Google