UI Flutter Lab Manual (1)
UI Flutter Lab Manual (1)
List of Experiments
Flutter installation
https://docs.flutter.dev/get-started/install/windows
dart installation
Step 2: Run the Dart installer and click on the Next button
Step 3: After the download is completed, set the PATH environment variable to
"C:\Program Files\Dart\dart-sdk\bin”
import "dart:io";
main(){
intnum,factorial=1;
for(int i=1;i<=num;i++) {
factorial=factorial*i;
}
print("Factorial of $num is $factorial");
Output:
import 'dart:io';
boolisPrime(N) {
for (var i = 2; i <= N / i; ++i) {
if (N % i == 0) {
return false;
}
}
return true;
}
void main() {
Output:
import 'dart:io';
void main() {
int a=0, b=1;
stdout.write('Enter n value: ');
var n = int.parse(stdin.readLineSync()!);
stdout.write(a);
stdout.write(' ');
stdout.write(b);
stdout.write(' ');
for(int i=3;i<=n; i ++){
int c=a+b;
stdout.write(c);
stdout.write(' ');
a=b;
b=c;
}
}
Output:
Text Widget:
import 'package:flutter/material.dart';
void main() {
runApp(constMyApp());
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Text Widget'),
),
body: Container(
child: Text(
'Hi, I am text widget',
style: TextStyle(
fontSize: 40,
color: Colors.red,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.italic,
letterSpacing: 3,
wordSpacing: 10,
backgroundColor: Colors.amber,
),
),
),
);
}
}
Container Widget
import 'package:flutter/material.dart';
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(35),
margin: EdgeInsets.all(20),
decoration: BoxDecoration(
border: Border.all(color: Colors.black, width: 4),
borderRadius: BorderRadius.circular(8),
boxShadow: [
newBoxShadow(color: Colors.green, offset: new Offset(6.0, 6.0),),
],
),
child: Text("Hello! I am in the container widget decoration box!!",
style: TextStyle(fontSize: 30),
textDirection: TextDirection.ltr
),
);
}
}
b) Implement different layout structures using Row, Column, and Stack widgets.
Row Widget
import 'package:flutter/material.dart';
void main() =>runApp(MyApp());
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Flutter Row Widget')
),
body: Row(
children:[
Expanded(
child: Text(' Column 1 ')),
Expanded(
child: Text(' Column 2 ')),
Expanded(
child: Text(' Column 3 '))])
));
}
}
Output:
Column Widget
import 'package:flutter/material.dart';
Output:
Stack Widget:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp() );
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: Text('Example'),
),
body: Container(
child:Center(
child: Stack(
children: [
Container(
color: Colors.red,
margin: EdgeInsets.all(30),
),
Container(
color: Colors.blue,
margin: EdgeInsets.all(70),
),
Container(
color: Colors.yellow,
margin: EdgeInsets.all(120),
),
],
),)
),
) );
}
}
Output:
Navigation:
import 'package:flutter/material.dart';
void main() {
runApp(constMaterialApp(
title: 'Navigation Basics',
home: FirstRoute(),
));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('First Route'),
),
body: Center(
child: ElevatedButton(
child: const Text('Open route'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) =>constSecondRoute()),
);
},
),
),
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Second Route'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
Output:
Named Routes
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
Result: The programs were executed successfully and verified the output
import'package:flutter/material.dart';
import'package:flutter_blog/screens/home_screen.dart';
import'package:flutter_blog/screens/post_screen.dart';
voidmain() =>runApp(MyApp());
classMyAppextendsStatelessWidget {
@override
Widgetbuild(BuildContext context) {
returnMaterialApp(
title: 'Flutter Blog',
theme: ThemeData(
primarySwatch: Colors.blue,
),
initialRoute: '/',
routes: {
'/': (context) =>HomeScreen(),
'/post': (context) =>PostScreen(),
},
);
}
}
classPostScreenextendsStatelessWidget {
@override
Widgetbuild(BuildContext context) {
finalargs = ModalRoute.of(context)!.settings.argumentsasMap<String,
dynamic>;
final post = args['post'];
returnScaffold(
appBar: AppBar(
title: Text('Flutter Blog'),
),
body: Center(
child: Text(post.title),
),
);
}
}