Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
55 views3 pages

Lab 6 Flutter

Download as txt, pdf, or txt
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 3

//Basic structure of stateful widget

import 'package:flutter/material.dart';

void main(){
runApp(MyApp());
}
class MyApp extends StatelessWidget {
List<String> titlelist = ["Irtaza","Danish","Halfbludd","shikka","Abdullah",];
List<String> subtitlelist = ["2K20-BSCS-153","2K20-BSCS-160","2K20-BSCS-
104","2K20-BSCS-110","2K20-BSCS-158",];
List<Icon> iconlist = [
Icon(Icons.person),
Icon(Icons.percent),
Icon(Icons.abc_rounded),
Icon(Icons.ac_unit_sharp),
Icon(Icons.zoom_in),
Icon(Icons.zoom_in_rounded),
Icon(Icons.call),
];

@override
Widget build(BuildContext context){
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Theory 5'),
backgroundColor: Color.fromARGB(255, 225, 21, 7),
),
body:
titlelist.length>0 ?
ListView.builder(
itemCount: titlelist.length,
itemBuilder:(context,index){
return Card(
margin: EdgeInsets.all(8),
elevation: 15,
child: ListTile(
title: Text(titlelist[index]),
subtitle: Text(subtitlelist[index]),
leading: iconlist[index],
trailing: Icon(Icons.call),
),
);
}
)
: Center(
child: Text('List is empty'),),
),
);
}
}
----------------------------------------------------------------
//To Create a simple button in stateful widget
import 'package:flutter/material.dart';

void main(){
runApp(MyApp());
}
class MyApp extends StatelessWidget{
@override
Widget build(BuildContext context){
return MaterialApp(
home:HomeScreen(),);
}
}
class HomeScreen extends StatefulWidget{
@override
State<StatefulWidget> createState(){
return HomeClass();
}

}
class HomeClass extends State<HomeScreen>{
@override
Widget build(BuildContext context){
return Scaffold(
appBar: AppBar(
title: Text('Stateful widget'),
backgroundColor: Color.fromARGB(255, 0, 3, 2),
),
body: Center(
child: Column(children: [
Text('Click the following button :)'),
ElevatedButton(
onPressed: () {
print('Button is pressed.');
},
child: Text('click me'),
),
],)
),
);
}
}
----------------------------------------------------------------
//button that click and shows number
import 'package:flutter/material.dart';

void main(){
runApp(MyApp());
}
class MyApp extends StatelessWidget{
@override
Widget build(BuildContext context){
return MaterialApp(
home:HomeScreen(),);
}
}
class HomeScreen extends StatefulWidget{
@override
State<StatefulWidget> createState(){
return HomeClass();
}

}
class HomeClass extends State<HomeScreen>{
int i=0;
@override
Widget build(BuildContext context){
return Scaffold(
appBar: AppBar(
title: Text('Stateful widget'),
backgroundColor: Color.fromARGB(255, 0, 3, 2),
),
body: Center(
child: Column(children: [
Text(
i.toString(),
style: TextStyle(fontSize: 40),),
Text('Click the following button :)'),
ElevatedButton(
onPressed: () {
setState((){
i = i + 1;
});

print('Button is pressed $i');


}
,child: Text('click me'),
)
],)
),
);
}
}

You might also like