Flutter User Registration & UI Basics
Flutter User Registration & UI Basics
EXPERIMENT NO - 1
Dart SDK is a pre-compiled version so we have to download and extract it only. For this
follow the below-given instructions: Step 1: Download Dart SDK. Download Dart SDK
from the Dart SDK archive page.
The URL is: [Link]
Click on DART SDK to download SDK for Windows 64-Bit Architecture. The download will start and
a zip file will be downloaded. Note: To download SDK for any other OS select OS of your choice.
Step 2: Extract the downloaded zip file. Extract the contents of downloaded zip file and after
extracting contents of zip file will be as shown:
Step 3: Running Dart. Now open bin folder and type “cmd” as given below:
1
UID Lab Record
2
UID Lab Record
Command Prompt will open with our desired path of bin folder and now type dart”.
And now we are ready to use dart through bin folder but setting up the path in environment
variables will ease our task of Step3 and we can run dart from anywhere in the file system using
command prompt.
Step 4: Setting up path in environment variables. Open Environment Variables from advanced
system settings and add Path in System Variables as depicted in image:
3
UID Lab Record
4
UID Lab Record
Now we are done to use Dart from anywhere in the file system.
Step 5: Run Dart Using cmd
5
UID Lab Record
Output:
The sum is 13
The diff is 7
The mul is 30
The div is 3.3333333333333335
void main() {
print("Enter number:");
int? number = [Link]([Link]()!);
print("The entered number is ${number}");
}
Output:
Enter number:
50
The entered number is 50
6
UID Lab Record
// [Link]
void main() {
// Variable declaration
21;
isPassed = true;
print("Hello, $name!");
>= 50) {
} else {
}
// Loop
// Function call
7
UID Lab Record
8
UID Lab Record
// Function definition
return a + b;
int age;
// Constructor Student([Link],
[Link]);
// Method
void display() {
9
UID Lab Record
10
UID Lab Record
import ‘package:flutter/[Link]';
void main() {
runApp(MyWidgetApp());
}
class MyWidgetApp extends StatelessWidget { @override
MaterialApp(
Scaffold(
SingleChildScrollView(
'Hello, Flutter!',
),
SizedBox(height: 20),
'[Link]
[Link]',
height: 150,
),
SizedBox(height: 20),
// Container Widget Container(
[Link](8), color:
11
UID Lab Record
12
UID Lab Record
TextStyle(color: [Link]),
),
),
],
),
),
),
);
13
UID Lab Record
14
UID Lab Record
b) Implement different layout structures using Row, Column, and Stack widgets. \
import 'package:flutter/[Link]';
MaterialApp(
Scaffold(
Column(
children: [
Icon(Icons.star_border),
],
),
SizedBox(height: 20),
children: [
Text('Item 1'),
Text('Item 2'),
Text('Item 3'),
],
),
SizedBox(height: 20),
15
UID Lab Record
16
UID Lab Record
height: 200,
color: [Link][100],
),
height: 100,
color: [Link][400],
),
Text( "Stacked!",
],
],
),
),
);
17
UID Lab Record
18
UID Lab Record
import 'package:flutter/[Link]';
void main() { runApp(MyResponsiveApp());
}
class MyResponsiveApp extends StatelessWidget { @override
MaterialApp(
LayoutBuilder(
MobileLayout();
TabletLayout();
} else {
return DesktopLayout();
},
),
),
);
19
UID Lab Record
20
UID Lab Record
긐
긏̂
긓ˆ
□
return Center(child: Text("_ 긓
긐
긏
□
_Tablet Layout", style: TextStyle(fontSize: 24)));
}
}
class DesktopLayout extends StatelessWidget { @override
냯
;
_Desktop Layout", style: TextStyle(fontSize: 28)));
return Center(child: Text("□
21
UID Lab Record
22
UID Lab Record
import 'package:flutter/[Link]';
void main() {
runApp(MyMediaQueryApp());
MaterialApp(
Scaffold(
ResponsiveWidget(),
),
);
screenHeight = [Link](context).[Link];
String screenType;
"Mobile";
"Tablet";
23
UID Lab Record
24
UID Lab Record
} else {
screenType = "Desktop";
Column(
Text(
TextStyle(fontSize: 18),
),
Text(
TextStyle(fontSize: 18),
),
'Layout: $screenType',
),
],
),
);
25
UID Lab Record
26
UID Lab Record
Scaffold(
[Link](
context,
);
},
),
),
);
Scaffold(
Center(
},
27
UID Lab Record
28
UID Lab Record
),
);
29
UID Lab Record
30
UID Lab Record
import 'package:flutter/[Link]';
void main() {
runApp(
MaterialApp(
initialRoute: '/', routes: {
'/': (context) => FirstNamedScreen(), '/second': (context) =>
SecondNamedScreen(),
},
));
Scaffold(
Center(
[Link](context, '/second');
},
),
),
);
Scaffold(
31
UID Lab Record
32
UID Lab Record
},
),
),
);
}
}
33
UID Lab Record
34
UID Lab Record
),
),
);
TextStyle(fontSize: 24),
);
35
UID Lab Record
36
UID Lab Record
import 'package:flutter/[Link]';
MaterialApp(
home: CounterWidget(),
);
}
class CounterWidget extends StatefulWidget {
@override
}
class _CounterWidgetState extends State<CounterWidget> { int _count
= 0;
_count++;
});
}
@override
Scaffold(
Center(
$_count',
),
),
_incrementCounter,
37
UID Lab Record
38
UID Lab Record
child: Icon([Link]),
),
);
}
}
39
UID Lab Record
40
UID Lab Record
import 'package:flutter/[Link]';
}
class CounterScreen extends StatefulWidget { @override
_CounterScreenState createState() => _CounterScreenState();
_counter = 0;
_counter++;
});
@override
Scaffold(
FloatingActionButton(
Icon([Link]),
),
);
41
UID Lab Record
42
UID Lab Record
Let’s go through a fully working Provider example step by step. I'll give you the complete structure
that you can copy, paste, and run directly in your Flutter project.
add:
dependencies: flutter:
sdk: flutter provider:
^6.0.0
,̀ File Structure
/lib
┣ [Link]
┗ counter_model.dart
import 'package:flutter/[Link]';
increment() {
_count++;
notifyListeners(); // This notifies all widgets listening to rebuild
}
}
43
UID Lab Record
44
UID Lab Record
'counter_model.dart';
return Scaffold(
appBar: AppBar(title: Text("Provider Example")), body: Center(
child: Text(
'Counter: ${[Link]}', style:
TextStyle(fontSize: 28),
),
),
floatingActionButton: FloatingActionButton( onPressed:
[Link],
child: Icon([Link]),
),
);
}
}
Output Behavior
45
UID Lab Record
46
UID Lab Record
}
class MyCustomWidgetApp extends StatelessWidget { @override
MaterialApp(
required [Link],
});
@override
child: Padding(
SizedBox(height: 10),
SizedBox(height: 5),
],
),
),
);
}
}
47
UID Lab Record
48
UID Lab Record
import 'package:flutter/[Link]';
void main() { runApp(MyThemedApp());
}
class MyThemedApp extends StatelessWidget { @override
ThemeData(
useMaterial3: true,
textTheme: TextTheme(
),
),
home: ThemeExampleScreen(),
);
Scaffold(
child: Column(
Text( 'Heading',
style: [Link](context).[Link],
),
49
UID Lab Record
50
UID Lab Record
SizedBox(height: 10),
Text(
style: [Link](context).[Link],
),
padding: [Link](12),
[Link].shade50,
borderRadius: [Link](12),
),
),
],
),
),
);
51
UID Lab Record
52
UID Lab Record
MaterialApp(
Scaffold(
UserForm(),
),
),
);
}
class UserForm extends StatefulWidget { @override
}
class _UserFormState extends State<UserForm> { String
name = '';
'Male';
@override
Column(
53
UID Lab Record
54
UID Lab Record
),
// Password field TextField(
),
// Gender dropdown
DropdownButton<String>( value:
gender,
gender = value!;
});
},
child: Text(g),
))
.toList(),
),
SizedBox(height: 20),
//Submitbutton
ElevatedButton(
onPressed: () {
print('Gender: $gender');
55
UID Lab Record
56
UID Lab Record
},
child: Text('Submit'),
),
],
);
57
UID Lab Record
58
UID Lab Record
import 'package:flutter/[Link]';
MaterialApp(
Scaffold(
Padding(
),
),
);
}
class _ValidatedUserFormState extends State<ValidatedUserForm> { final
_formKey = GlobalKey<FormState>();
gender = 'Male';
@override
Form(
59
UID Lab Record
60
UID Lab Record
children: [
// Name TextFormField(
return null;
},
),
// Email TextFormField(
(value) {
return null;
},
),
// Password TextFormField(
true,
validator: (value) {
61
UID Lab Record
62
UID Lab Record
return null;
},
),
// Gender dropdown
DropdownButtonFormField<String>( value:
gender,
child: Text(label),
))
.toList(),
),
SizedBox(height: 20),
// Submit Button
ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
[Link](context).showSnackBar( SnackBar(content:
);
print('Name: $name');
print('Email: $email');
print('Password: $password');
print('Gender: $gender');
}
63
UID Lab Record
64
UID Lab Record
},
child: Text('Submit'),
),
],
),
);
}
}
65
UID Lab Record
66
UID Lab Record
import 'package:flutter/[Link]';
void main() => runApp(FadeAnimationApp());
class FadeAnimationApp extends StatelessWidget { @override
MaterialApp(
home: FadeDemo(),
);
}
class FadeDemo extends StatefulWidget { @override
}
class _FadeDemoState extends State<FadeDemo> { double
opacityLevel = 1.0;
});
}
@override
Widget build(BuildContext context) { return
Scaffold(
opacityLevel, duration:
width: 200,
height: 200,
color: [Link],
),
),
67
UID Lab Record
68
UID Lab Record
),
_toggleOpacity,
child: Icon([Link]),
),
);
69
UID Lab Record
70
UID Lab Record
import 'package:flutter/[Link]';
void main() => runApp(SlideAnimationApp());
class SlideAnimationApp extends StatelessWidget {
@override
MaterialApp(
home: SlideDemo(),
);
}
class SlideDemo extends StatefulWidget { @override
false;
@override
Scaffold(
children: [ AnimatedPositioned(
top: 100,
100,
height: 100,
color: [Link],
),
71
UID Lab Record
72
UID Lab Record
),
],
),
() {
setState(() {
moved = !moved;
});
},
child: Icon(Icons.play_arrow),
),
);
73
UID Lab Record
74
UID Lab Record
import 'package:flutter/[Link]';
import 'dart:convert';
void main() => runApp(ApiSimulationApp());
class ApiSimulationApp extends StatelessWidget {
@override
MaterialApp(
PostListScreen(),
);
}
}
class Post { final int id;
body;
json['title'],
body: json['body'],
);
}
class PostListScreen extends StatefulWidget { @override
}
class _PostListScreenState extends State<PostListScreen> { late
Future<List<Post>> posts;
@override
void initState() {
[Link](); posts =
fetchPosts();
75
UID Lab Record
76
UID Lab Record
sampleJson = '''
''';
}
@override
Scaffold(
FutureBuilder<List<Post>>(
future: posts,
margin: [Link](10),
child: ListTile(
Text([Link]),
),
);
}).toList(),
);
77
UID Lab Record
78
UID Lab Record
} else if ([Link]) {
},
),
);
79
UID Lab Record
80
UID Lab Record
import 'package:flutter/[Link]';
import 'dart:convert';
void main() => runApp(ApiDisplayApp());
MaterialApp(
PostListScreen(),
);
}
}
class Post { final int id;
body;
json['title'],
body: json['body'],
);
}
class _PostListScreenState extends State<PostListScreen> { late
Future<List<Post>> posts;
@override
81
UID Lab Record
82
UID Lab Record
title: Text([Link],
Text([Link]),
),
);
},
);
} else if ([Link]) {
} else {
},
),
);
83
UID Lab Record
84
UID Lab Record
In Flutter, we typically write widget tests (UI component tests) using the flutter_test package.
DartPad does not support test files. You must run this in VS Code / Android Studio / terminal.
¸
,̀
/5Q Step 1: Create a simple UI component
// lib/counter_widget.dart
import
'package:flutter/[Link]';
@override
Widget build(BuildContext context) { return
Column(
children: [
Text('Count: $count', key: Key('counterText')),
ElevatedButton(
key: Key('incrementButton'), onPressed:
increment,
child: Text('Increment'),
),
],
);
}
}
^
`
Step 2: Write Unit/Widget Test
85
UID Lab Record
86
UID Lab Record
import 'package:flutter/[Link]';
import 'package:flutter_test/flutter_test.dart';
import 'package:your_app/counter_widget.dart'; // Adjust import path
void main() {
testWidgets('Counter increments when button is pressed', (WidgetTester tester) async { await
[Link](
MaterialApp(home: Scaffold(body: CounterWidget())),
);
// Initial state
expect([Link]('Count: 0'), findsOneWidget);
flutter test
Tool Usage
Flutter DevTools Memory, widget tree, performance profiling
debugPrint() Log internal values in your widget/state
flutter run --debug Runs app in debug mode with hot reload
breakpoints (VS Code/Android Studio) Inspect variable state at runtime
flutter analyze Check for errors, lints, dead code
*
˛ Common Debugging Tips:
87
UID Lab Record
88
UID Lab Record
˙Q
•Example Fix: Widget not rebuilding?
89
UID Lab Record
90
UID Lab Record
class Person {
int id;
String name;
int age;
Person({required [Link], required [Link], required [Link]});
}
setState(() {
_fakeDb.add(Person(id: _nextId++, name: name, age: age));
_nameController.clear();
_ageController.clear();
});
}
91
UID Lab Record
92
UID Lab Record
// Delete a record by id
void _deleteRecord(int id) {
setState(() {
_fakeDb.removeWhere((person) => [Link] == id);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Fake SQLite in DartPad'),
),
body: Padding(
padding: const [Link](16),
child: Column(
children: [
// Input fields
TextField(
controller: _nameController,
decoration: InputDecoration(labelText: 'Name'),
),
TextField(
controller: _ageController,
decoration: InputDecoration(labelText: 'Age'),
keyboardType: [Link],
),
SizedBox(height: 10),
ElevatedButton(
onPressed: _addRecord,
child: Text('Add Record'),
),
SizedBox(height: 20),
// List of records
Expanded(
child: _fakeDb.isEmpty
? Center(child: Text('No records yet'))
: [Link](
itemCount: _fakeDb.length,
itemBuilder: (context, index) {
final person = _fakeDb[index];
return ListTile(
title: Text([Link]),
subtitle: Text('Age: ${[Link]}'),
trailing: IconButton(
icon: Icon([Link]),
onPressed: () => _deleteRecord([Link]),
),
);
},
),
),
],
),
93
UID Lab Record
94
UID Lab Record
import 'package:flutter/[Link]';
class Person {
int id;
String name;
int age;
Person({required [Link], required [Link], required [Link]});
}
Person? _editingPerson;
void _clearInputs() {
_nameController.clear();
_ageController.clear();
_editingPerson = null;
}
void _addOrUpdateRecord() {
final name = _nameController.[Link]();
final ageText = _ageController.[Link]();
if ([Link] || [Link]) return;
setState(() {
if (_editingPerson == null) {
95
UID Lab Record
96
UID Lab Record
// Create
_people.add(Person(id: _nextId++, name: name, age: age));
} else {
// Update
_editingPerson!.name = name;
_editingPerson!.age = age;
}
_clearInputs();
});
}
@override
Widget build(BuildContext context) {
final isEditing = _editingPerson != null;
return Scaffold(
appBar: AppBar(
title: Text('Basic CRUD Demo'),
),
body: Padding(
padding: const [Link](16),
child: Column(
children: [
// Input Fields
TextField(
controller: _nameController,
decoration: InputDecoration(labelText: 'Name'),
),
TextField(
controller: _ageController,
decoration: InputDecoration(labelText: 'Age'),
keyboardType: [Link],
),
SizedBox(height: 10),
Row(
children: [
ElevatedButton(
onPressed: _addOrUpdateRecord,
97
UID Lab Record
98
UID Lab Record
// List of records
Expanded(
child: _people.isEmpty
? Center(child: Text('No records yet'))
: [Link](
itemCount: _people.length,
itemBuilder: (context, index) {
final person = _people[index];
return ListTile(
title: Text([Link]),
subtitle: Text('Age: ${[Link]}'),
onTap: () => _startEdit(person),
trailing: IconButton(
icon: Icon([Link]),
onPressed: () => _deleteRecord([Link]),
),
);
},
),
),
],
),
),
);
}
}
99