You are on page 1of 6

List Application

import 'package:flutter/material.dart';
import 'package:tap_app/newlecture/class.dart';
class Country {
String name;
String flag;
String capitalcity;
Country({
required this.name,
this.flag = '',
this.capitalcity = '',
}); }
class MyList extends StatelessWidget {
MyList({super.key});
final List<Country> mycn = [
Country(
name: 'Pakistan',
flag: 'https://www.worldometers.info/img/flags/small/tn_pk-flag.gif',
capitalcity: 'Islamabaad'),
Country(
name: 'China',
flag: 'https://www.worldometers.info/img/flags/small/tn_ch-flag.gif',
capitalcity: 'Bejing'),
Country(
name: 'Saudia Arab',
flag: 'https://www.worldometers.info/img/flags/small/tn_sa-flag.gif',
capitalcity: 'Riyadh'),
Country(
name: 'India',
flag: 'https://www.worldometers.info/img/flags/small/tn_in-flag.gif',
capitalcity: 'Delhi'), ];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Simple List'),
),
body: Container(
child: ListView.builder(
itemCount: mycn.length,
itemBuilder: (context, index) {
return Card(
margin: EdgeInsets.symmetric(horizontal: 16, vertical: 6),
child: InkWell(
onTap: () {},
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(children: [
Container(
width: 80,
margin: EdgeInsets.only(right: 14),
child: ClipRRect(
borderRadius: BorderRadius.circular(6),
child: Image.network(
mycn[index].flag, ))),
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
mycn[index].name,
style: TextStyle(fontSize: 20), ),
SizedBox(
height: 6, ),
Text(
mycn[index].capitalcity,
style: TextStyle(color: Colors.black87),
), ], )) ]), ), ), ); }, ), ), ); } }

Dice Application
import 'dart:math';
import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/material.dart';
class DiceApp extends StatefulWidget {
const DiceApp({super.key});
@override
State<DiceApp> createState() => _DiceAppState();}
class _DiceAppState extends State<DiceApp> {
int numb = 1;
int numb1 = 1;
AudioPlayer player = AudioPlayer();
void dice() {
// Marked function as async
setState(() {
numb = Random().nextInt(6) + 1;
numb1 = Random().nextInt(6) + 1;
player.play(AssetSource('my.mp3')); });}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color.fromARGB(255, 115, 7, 173),
body: Container(
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 100,
width: 100,
child: Image.asset('assets/images/dice$numb.png'), ),
SizedBox(
width: 20, ),
Container(
height: 100,
width: 100,
child: Image.asset('assets/images/dice$numb1.png'), ) ] ),
ElevatedButton(
onPressed: () {
dice();
},
child: Text('tap me')) ],),), ); }}

Random Generator Application


import 'dart:math';
import 'package:flutter/material.dart';
class Randon_numb extends StatefulWidget {
const Randon_numb({
super.key,});
@override
State<Randon_numb> createState() => _Randon_numbState();}
class _Randon_numbState extends State<Randon_numb> {
int _counter = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
width: double.infinity,
color: Colors.blue,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Tap For Random Number',
style: TextStyle(fontSize: 25),),
SizedBox(
height: 8,),
Text(
'$_counter',
style: TextStyle(fontSize: 35, fontWeight: FontWeight.bold),),
SizedBox(
height: 8,),
Container(
height: 44,
width: 100,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.cyan,
foregroundColor: Colors.white,
shape: CircleBorder(),),
onPressed: () {
setState(() {
_counter = Random().nextInt(10) + 2;
});},
child: Text(
'TAP',
style: TextStyle(fontSize: 15),),),),
TextButton(
onPressed: () {
setState(() {
_counter = 0;});},
child: Text(
'Reset',
style: TextStyle(fontSize: 15),),), ],),)); }}

Drawer

import 'package:flutter/material.dart';
class mydraw extends StatefulWidget {
const mydraw({super.key});
@override
State<mydraw> createState() => _mydrawState();
}
class _mydrawState extends State<mydraw> {
int slectedindex = 0;
int bottomindex = 0;
final pages = [
myhome(),
myprofile(),
mysettings(), ];
void changeindex(int index) {
setState(() {
slectedindex = index; });
Navigator.of(context).pop(); }
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Welcome'),
actions: [
IconButton(
onPressed: () {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text('Hi, i am star'))); },
icon: Icon(Icons.star)),
IconButton(
onPressed: () {
showDialog(
context: context,
builder: (ctx) {
return AlertDialog(
title: Text('Important'),
content: Text('Are you sure to proceed ?'),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop(); },
child: Text('No')),
TextButton(
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
backgroundColor: Colors.green,
content: Text(
'Thank you for confirmation.')));
Navigator.of(context).pop(); }, child: Text('Yes')) ); }, ); },
icon: Icon(Icons.shopping_cart)),
IconButton(
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Hi, i am setting'))); },
icon: Icon(Icons.settings)) ], ),
drawer: Drawer(
child: Column(
children: [
DrawerHeader(
child: Container(
width: double.infinity,
padding: EdgeInsets.all(6),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(
'My App',
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 20), ),
Text('App slogan goes here'), ], ), ), ),
ListTile(
onTap: () {
changeindex(0); },
selected: slectedindex == 0,
leading: Icon(Icons.home),
title: Text('home'), ),
ListTile(
onTap: () {
changeindex(1); },
selected: slectedindex == 1,
leading: Icon(Icons.person),
title: Text('Profile'), ),
ListTile(
onTap: () {
changeindex(2); },
selected: slectedindex == 2,
leading: Icon(Icons.settings),
title: Text('Settings'), ),
Divider(),
ListTile(
onTap: () {
setState(() {
slectedindex = 3; });
Navigator.of(context).pop(); },
selected: slectedindex == 3,
leading: Icon(Icons.apps),
title: Text('categories'), ),
ListTile(
onTap: () {
setState(() {
slectedindex = 4; });
Navigator.of(context).pop(); },
selected: slectedindex == 4,
leading: Icon(Icons.history),
title: Text('Recent'), ),
ListTile(
onTap: () {
setState(() {
slectedindex = 5; });
Navigator.of(context).pop(); },
selected: slectedindex == 5,
leading: Icon(Icons.money),
title: Text('My orders'), ) ], ), ),
body: pages[(bottomindex)],
bottomNavigationBar: BottomNavigationBar(
currentIndex: bottomindex,
type: BottomNavigationBarType.fixed,
showUnselectedLabels: false,
items: [
BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'),
BottomNavigationBarItem(icon: Icon(Icons.person), label: 'Profile'),
BottomNavigationBarItem(
icon: Icon(Icons.settings), label: 'Settings'),
BottomNavigationBarItem(icon: Icon(Icons.apps), label: 'Orders'),
BottomNavigationBarItem(icon: Icon(Icons.history), label: 'Recent'),
],
onTap: (value) {
setState(() {
bottomindex = value; }); }, )); }}

You might also like