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)
So, your code should look like this, using the BLoC pattern.
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.
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.
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.
How to Effectively Hire and Manage a Remote Team of Developers.
Download NowWe had very close go live timeline and MindBowser team got us live a month before.
CEO, BuyNow WorldWide
If you want a team of great developers, I recommend them for the next project.
Founder, Teach Reach
Mindbowser built both iOS and Android apps for Mindworks, that have stood the test of time. 5 years later they still function quite beautifully. Their team always met their objectives and I'm very happy with the end result. Thank you!
Founder, Mindworks
Our CISO was extremely impressed by Mindbowser’s work. It is pretty rare to see this kind of clean security report so early in the company’s journey. Huge Thank you for the disciplined approach here.
Founder, TrestleIQ
Mindbowser has delivered a much better quality product than our previous tech vendors. Our product is stable and passed Well Architected Framework Review from AWS.
CEO, PurpleAnt
The flexibility and capacity of the Mindbower staff has been impressive.
CEO, ProofPilot
I am happy to share that we got USD 10k in cloud credits courtesy of our friends at Mindbowser. Thank you Pravin and Ayush, this means a lot to us.
CTO, Shortlist
Mindbowser is one of the reasons that our app is successful. These guys have been a great team.
Founder & CEO, MangoMirror
Kudos for all your hard work and diligence on the Telehealth platform project. You made it possible.
CEO, ThriveHealth
Mindbowser helped us build an awesome iOS app to bring balance to people’s lives.
CEO, SMILINGMIND
They were a very responsive team! Extremely easy to communicate and work with!
Founder & CEO, TotTech
We’ve had very little-to-no hiccups at all—it’s been a really pleasurable experience.
Co-Founder, TEAM8s
Mindbowser was very helpful with explaining the development process and started quickly on the project.
Executive Director of Product Development, Innovation Lab
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.
Co-Founder, Vesica
Mindbowser is professional, efficient and thorough.
Consultant, XPRIZE
Very committed, they create beautiful apps and are very benevolent. They have brilliant Ideas.
Founder, S.T.A.R.S of Wellness
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.
Co-Founder, Flat Earth
Ayush was responsive and paired me with the best team member possible, to complete my complex vision and project. Could not be happier.
Founder, Child Life On Call
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.
Founder, Courtyardly
The team from Mindbowser stayed on task, asked the right questions, and completed the required tasks in a timely fashion! Strong work team!
CEO, SDOH2Health LLC
Mindbowser was easy to work with and hit the ground running, immediately feeling like part of our team.
CEO, Stealth Startup
Mindbowser was an excellent partner in developing my fitness app. They were patient, attentive, & understood my business needs. The end product exceeded my expectations. Thrilled to share it globally.
Owner, Phalanx
Mindbowser's expertise in tech, process & mobile development made them our choice for our app. The team was dedicated to the process & delivered high-quality features on time. They also gave valuable industry advice. Highly recommend them for app development...
Co-Founder, Fox&Fork
We cannot express enough how pleased we are with the entire Mindbowser team. From our first call, they focused on our vision and ensured things were handled as per requirement. Communication was so easy and flexible to our schedule. I’m...
Founder, SafeZone Safety Systems