(PRAC 0)ALL
Practical 2 code:
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('Practical 2'),
backgroundColor: Colors.purple,
),
drawer: const Drawer(
child: Center(
child: Text(style:TextStyle(fontSize: 20),'425_Devesh_Ghadigaonkar'),
),
),
body: const Center(
child: Image(
image: NetworkImage(
'https://static1.anpoimages.com/wordpress/wp-content/uploads/2022/06/Android-13-now-purple-widgets-spread.jpg'),
),
)),
),
);
}
Practical 3A code:(single-Child Layout widget)
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('Practical 3A'),
backgroundColor: Color.fromARGB(255, 251, 17, 0)),
body: Center(
//centering the container
child: Padding(
padding: EdgeInsets.all(10),
child: SizedBox(
//enforcing the sized box height and width on containers height and width
height: 200,
width: 200,
child: Container(
//container
width: 100,
height: 100,
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [Colors.white, Colors.lime, Colors.black],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
child: const Center(
child: Text('425_Devesh_Ghadigaonkar',
style: TextStyle(fontSize: 18),
textAlign: TextAlign.center),
),
),
),
),
),
),
),
);
}
Practical 3B (multi- child Layout widget):
Column :
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('Practical 3B'),
backgroundColor: Color.fromARGB(255, 234, 124, 7)
),
body : Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children:[
Container(
child: const Text('425_Devesh',textAlign: TextAlign.center,style: TextStyle(fontSize: 18),),
width: 200,
height:200,
//color:Colors.amber,
decoration: const BoxDecoration(
gradient: LinearGradient(
colors:[Colors.orange,Colors.white,Colors.green],
begin:Alignment.topLeft,
end:Alignment.bottomRight,
),
),
),
Container(
child: const Text('Ghadigaonkar',textAlign: TextAlign.center,style: TextStyle(fontSize: 18),),
width: 200,
height:200,
//color:Colors.amber,
decoration: const BoxDecoration(
gradient: LinearGradient(
colors:[Colors.orange,Colors.white,Colors.green],
begin:Alignment.topLeft,
end:Alignment.bottomRight,
),
),
),
],
),
),
),
),
);
}
Row :
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('Practical 3B'),
backgroundColor: Color.fromARGB(255, 0, 177, 241)
),
body : Center(
child: Row(
mainAxisSize: MainAxisSize.min,
children:[
Container(
child: const Text('425_Devesh',textAlign: TextAlign.center,style: TextStyle(fontSize: 20),),
width: 200,
height:200,
decoration: const BoxDecoration(
gradient: LinearGradient(
colors:[Colors.orange,Colors.white,Colors.green],
begin:Alignment.topLeft,
end:Alignment.bottomRight,
),
),
),
Container(
child: const Text('Ghadigaonkar',textAlign: TextAlign.center,style: TextStyle(fontSize: 20),),
width: 200,
height:200,
decoration: const BoxDecoration(
gradient: LinearGradient(
colors:[Colors.orange,Colors.white,Colors.green],
begin:Alignment.topLeft,
end:Alignment.bottomRight,
),
),
),
],
),
),
),
),
);
}
Expanded :
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body:Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children:[
Expanded(
child: Container(
color: const Color.fromARGB(255, 251, 19, 3),
width:100,
height:100,
child: const Text('Roll No. 425',textAlign: TextAlign.center,style:TextStyle(fontSize: 20)),
),
),
Align(
alignment: Alignment.center,
child:Container(
color: Color.fromARGB(255, 251, 251, 0),
width:100,
height:100,
child: const Text('Devesh',textAlign: TextAlign.center,style:TextStyle(fontSize: 20)),
),
),
Expanded(
child: Container(
color: Colors.blue,
width:100,
height:100,
child: const Text('Ghadigaonkar',textAlign: TextAlign.center,style:TextStyle(fontSize: 20)),
),
),
]
),
),
),
),
);
}
Listview :
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body:Center(
child: ListView(
children:[
Container(
color:Colors.green,
width:200,
height:300,
child: Text('Roll No. 425',textAlign: TextAlign.center,),
),
Container(
color:Colors.lightGreenAccent,
width:200,
height:200,
child: Text('Devesh',textAlign: TextAlign.center,),
),
Container(
color:Colors.cyanAccent,
width:200,
height:300,
child:Text('Ghadigaonkar',textAlign: TextAlign.center,),
),
]
),
),
),
),
);
}
Gridview :
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: GridView(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 4 ),
children: [
Container(
color: Colors.amber,
width: 300,
height: 300,
child: Text('Roll No. 425'),
),
Container(
color: Color.fromARGB(255, 2, 222, 238),
width: 300,
height: 300,
child: Text('Devesh'),
),
Container(
color: Color.fromARGB(255, 239, 249, 44),
width: 300,
height: 300,
child: Text('Ghadigaonkar'),
),
Container(
color: Color.fromARGB(255, 41, 252, 4),
width: 300,
height: 300,
child: Text('hello'),
),
Container(
color: Color.fromARGB(255, 134, 78, 225),
width: 300,
height: 300,
child: Text('hello'),
),
],
),
))));
}
Stack :
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body:Center(
child: Stack(
alignment: Alignment.bottomCenter,
children:[
Container(
color:Colors.green,
width:300,
height:300,
child: Text('425',style: TextStyle(fontSize: 20),),
),
Container(
color:Colors.lightGreenAccent,
width:200,
height:200,
child: Text('Devesh',style: TextStyle(fontSize: 20)),
),
Container(
color:Colors.amber,
width:100,
height:150,
child:Text('Ghadigaonkar',style: TextStyle(fontSize: 20)),
),
]
),
),
),
),
);
}
Practical 4
#main.dart
import 'package:flutter/material.dart';
import 'Practical 4.dart';
void main() {
runApp(
MaterialApp(
title: '425_Devesh Ghadigaonkar',
home: GestureDemo(), //Calling your GestureDemo class
),
);
}
#Practical 4.dart
import 'dart:math';
import 'package:flutter/material.dart';
//Step 1
class GestureDemo extends StatefulWidget {
const GestureDemo({super.key});
@override
State<GestureDemo> createState() {
return _GestureDemo();
}
}
//Step 2
class _GestureDemo extends State<GestureDemo> {
var numtime = 0; // created variable for getting number of times tapped
Color changebgcolor = Colors.red; //created variable of datatype color
final randomizer = Random();
var generaterandom = 1;
//Created function for incrementing count of times container was clicked
void noofTimes() {
setState(() {
numtime += 1;
});
}
//Created function for changing color of heart icon
void changebg() {
setState(() {
if (changebgcolor == Colors.red) {
changebgcolor = const Color.fromARGB(255, 209, 115, 226);
} else {
changebgcolor = Colors.red;
}
});
}
//Created function for generating random no.
void randomNo(){
setState(() {
generaterandom= randomizer.nextInt(10)+1;
});
}
@override
Widget build(context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
//onTap Gesture example
Text(
'Tapped $numtime times',
style: TextStyle(fontSize: 25),
),
SizedBox(height: 15),
GestureDetector(
onTap: () {
noofTimes();
},
child: Container(
color: Colors.amber,
padding: const EdgeInsets.all(20),
child: const Text(
'Single Tap here',
style: TextStyle(fontSize: 20),
),
),
),
const SizedBox(
height: 40,
),
//onDoubleTap Gesture
Icon(Icons.favorite, size: 60, color: changebgcolor), // To Add an Icon
const SizedBox(height: 10),
GestureDetector(
onDoubleTap: () {
changebg();
},
child: Container(
color: Colors.black,
padding: EdgeInsets.all(20),
child: const Text(
'Double Tap here',
style: TextStyle(fontSize: 20, color: Colors.white),
),
),
),
const SizedBox(
height: 50,
),
//onLongTap Gesture
Text('Random no. generated between 1 to 10:\n $generaterandom', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),),
const SizedBox(
height: 10,
),
GestureDetector(
onLongPress: () {
randomNo();
},
child: Container(
color: Colors.lime,
padding: EdgeInsets.all(20),
child: const Text(
'Long Press here',
style: TextStyle(fontSize: 20),
),
),
),
],
),
),
);
}
}
Practical 5
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
title: "Practical 5",
theme: ThemeData(
primaryColor: Colors.deepPurple,
primarySwatch: Colors.purple,
fontFamily: 'Times New Roman',
textTheme: TextTheme(
titleLarge: TextStyle(
fontSize: 50,
fontWeight: FontWeight.bold,
color: Colors.cyan,
),
bodyMedium: TextStyle(
fontSize: 20,
fontFamily: 'Arial',
),
),
),
home: HomePage(),
),
);
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Home Page'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('425_Devesh'),
Text(
'HeadLine',
style: Theme.of(context).textTheme.titleLarge,
),
SizedBox(height: 20),
Text('SubTitle', style: Theme.of(context).textTheme.bodyLarge),
SizedBox(height: 20),
Container(
color: Theme.of(context).primaryColor,
height: 50,
width: 50,
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SecondPage(),
),
);
},
child: Text('Next Page'),
),
],
),
),
);
}
}
class SecondPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Second Page'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
child: Text('Home Page'),
),
),
);
}
}
Practical 6
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
initialRoute: '/',
routes: {
'/':(context) => FirstScreen(),
'/second':(context) => SecondScreen(),
},
),
);
}
class FirstScreen extends StatelessWidget {
@override
Widget build(context) {
return Scaffold(
appBar: AppBar(
title: Text('425_FirstScreen'),
),
body: Center(
child: ElevatedButton(
onPressed: () {Navigator.pushNamed(
context, '/second',
);},
child: Text('Next Screen'),
),
),
);
}
}
class SecondScreen extends StatelessWidget {
@override
Widget build(context) {
return Scaffold(
appBar: AppBar(
title: Text('425_Second Screen'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
child: Text('First Screen'),
),
),
);
}
}
Practical 7
#Practical 7.dart
import 'package:flutter/material.dart';
import 'package:myapp/animedemo.dart';
void main()
{
runApp(
MaterialApp(
home: Animedemo(),
),
);
}
#animedemo.dart
import 'package:flutter/material.dart';
class Animedemo extends StatefulWidget {
State<Animedemo> createState(){
return _AnimedemoState();
}
}
class _AnimedemoState extends State<Animedemo>{
double _margin = 0;
double _width = 200;
Color _color = Colors.greenAccent;
@override
Widget build(context){
return Scaffold(
body: Center(
child: AnimatedContainer(
margin: EdgeInsets.all(_margin),
duration: Duration(seconds: 1),
width: _width,
color: _color,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
setState(() {
_margin = 50;
});
},
child: Text ('Animate margin'),
),
SizedBox(
height: 15,
),
ElevatedButton(
onPressed: (){
setState(
() {
_color = Colors.yellowAccent;
},
);
}, child: Text('Animate Color'),
),
SizedBox(
height: 15,
),
ElevatedButton(
onPressed: (){
setState(
() {
_width = 400;
},
);
}, child: Text('Animate Width'),
),
],
)
)
)
);
}
}
Practical 8
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
//_MyAppState createState() => _MyAppState();
State<MyApp> createState(){
return _MyAppState();
}
}
class _MyAppState extends State<MyApp> {
//state of the widget
Color _containerColor = Colors.yellow;
void changeColor() {
setState(() {
if (_containerColor == Colors.yellow) {
_containerColor = Colors.green;
return;
}
_containerColor = Colors.yellow;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Hello World',
theme: ThemeData(primarySwatch: Colors.blue),
home: Scaffold(
appBar: AppBar(
title: Text('Hello'),
),
body: Container(color: _containerColor),
// ),
floatingActionButton: FloatingActionButton(onPressed: changeColor, child: Icon(Icons.add),tooltip: 'Click me',),
),
);
}
}
Comments
Post a Comment