0% found this document useful (0 votes)
17 views10 pages

Flutter

Uploaded by

oasispro91
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views10 pages

Flutter

Uploaded by

oasispro91
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

To create a Flutter UI in Visual Studio Code, you can set up and develop a simple registration form with

multiple screens. Here’s a step-by-step guide for each component of the registration UI:

1. Set Up the Project in VS Code

Open VS Code and ensure you have the Flutter extension installed.

Create a New Flutter Project by opening the command palette (Ctrl + Shift + P), typing Flutter: New
Project, and selecting your folder.

2. Build the UI Code for Each Registration Screen

The following are code snippets for building each part of the UI in Flutter using VS Code.

A. Personal Information Screen

Add a screen that collects user information such as name, email, and phone number. Create a new file,
personal_info_screen.dart, and add the following code:

dart

Copy code

import 'package:flutter/material.dart';

class PersonalInfoScreen extends StatelessWidget {

final _formKey = GlobalKey<FormState>();

@override

Widget build(BuildContext context) {

return Scaffold(

appBar: AppBar(title: Text('Personal Information')),

body: Padding(
padding: const EdgeInsets.all(16.0),

child: Form(

key: _formKey,

child: Column(

children: <Widget>[

TextFormField(

decoration: InputDecoration(labelText: 'Full Name'),

validator: (value) => value == null || value.isEmpty ? 'Enter your name' : null,

),

TextFormField(

decoration: InputDecoration(labelText: 'Email Address'),

validator: (value) => value == null || !value.contains('@') ? 'Enter a valid email' : null,

),

TextFormField(

decoration: InputDecoration(labelText: 'Phone Number'),

keyboardType: TextInputType.phone,

validator: (value) => value == null || value.length < 10 ? 'Enter a valid phone number' : null,

),

ElevatedButton(

onPressed: () {

if (_formKey.currentState!.validate()) {

Navigator.pushNamed(context, '/credentials');

},

child: Text('Next'),
),

],

),

),

),

);

B. Account Credentials Screen

This screen will collect the username, password, and offer a two-factor authentication option. Create a
file account_credentials_screen.dart:

dart

Copy code

import 'package:flutter/material.dart';

class AccountCredentialsScreen extends StatelessWidget {

final _formKey = GlobalKey<FormState>();

@override

Widget build(BuildContext context) {

return Scaffold(

appBar: AppBar(title: Text('Account Credentials')),

body: Padding(

padding: const EdgeInsets.all(16.0),

child: Form(
key: _formKey,

child: Column(

children: <Widget>[

TextFormField(

decoration: InputDecoration(labelText: 'Username'),

validator: (value) => value == null || value.isEmpty ? 'Enter a username' : null,

),

TextFormField(

decoration: InputDecoration(labelText: 'Password'),

obscureText: true,

validator: (value) => value == null || value.length < 6 ? 'Password must be at least 6
characters' : null,

),

SwitchListTile(

title: Text('Enable Two-Factor Authentication'),

value: true,

onChanged: (bool value) {},

),

ElevatedButton(

onPressed: () {

if (_formKey.currentState!.validate()) {

Navigator.pushNamed(context, '/meterInfo');

},

child: Text('Next'),

),
],

),

),

),

);

C. Meter Information Screen

Create another screen to gather the meter number and location. Save this as meter_info_screen.dart:

dart

Copy code

import 'package:flutter/material.dart';

class MeterInfoScreen extends StatelessWidget {

final _formKey = GlobalKey<FormState>();

@override

Widget build(BuildContext context) {

return Scaffold(

appBar: AppBar(title: Text('Meter Information')),

body: Padding(

padding: const EdgeInsets.all(16.0),

child: Form(

key: _formKey,
child: Column(

children: <Widget>[

TextFormField(

decoration: InputDecoration(labelText: 'Meter Number'),

validator: (value) => value == null || value.isEmpty ? 'Enter your meter number' : null,

),

TextFormField(

decoration: InputDecoration(labelText: 'Meter Location'),

validator: (value) => value == null || value.isEmpty ? 'Enter the meter location' : null,

),

ElevatedButton(

onPressed: () {

if (_formKey.currentState!.validate()) {

Navigator.pushNamed(context, '/payment');

},

child: Text('Next'),

),

],

),

),

),

);

}
D. Payment Preferences Screen

Finally, this screen will allow users to select their payment method. Save this as
payment_preferences_screen.dart:

dart

Copy code

import 'package:flutter/material.dart';

class PaymentPreferencesScreen extends StatelessWidget {

final _formKey = GlobalKey<FormState>();

@override

Widget build(BuildContext context) {

return Scaffold(

appBar: AppBar(title: Text('Payment Preferences')),

body: Padding(

padding: const EdgeInsets.all(16.0),

child: Form(

key: _formKey,

child: Column(

children: <Widget>[

DropdownButtonFormField(

decoration: InputDecoration(labelText: 'Payment Method'),

items: [

DropdownMenuItem(child: Text('M-Pesa'), value: 'mpesa'),

DropdownMenuItem(child: Text('Tigo Pesa'), value: 'tigopesa'),


DropdownMenuItem(child: Text('Card Payment'), value: 'card'),

],

onChanged: (value) {},

),

TextFormField(

decoration: InputDecoration(labelText: 'Mobile Number/Card Number'),

keyboardType: TextInputType.number,

validator: (value) => value == null || value.isEmpty ? 'Enter your payment number' : null,

),

ElevatedButton(

onPressed: () {

if (_formKey.currentState!.validate()) {

// Registration complete

},

child: Text('Complete Registration'),

),

],

),

),

),

);

E. Navigation Setup
In your main.dart, set up navigation for each screen:

dart

Copy code

import 'package:flutter/material.dart';

import 'personal_info_screen.dart';

import 'account_credentials_screen.dart';

import 'meter_info_screen.dart';

import 'payment_preferences_screen.dart';

void main() {

runApp(MaterialApp(

initialRoute: '/',

routes: {

'/': (context) => PersonalInfoScreen(),

'/credentials': (context) => AccountCredentialsScreen(),

'/meterInfo': (context) => MeterInfoScreen(),

'/payment': (context) => PaymentPreferencesScreen(),

},

));

Run the App

In VS Code’s terminal, run:

bash
Copy code

flutter run

This will open the app on your emulator or connected device, showing the registration flow UI screens
step-by-step for SyncIT.

Would you like to add any specific features, like secure token handling or enhanced UI design?

You might also like