Dart Programing
Basic :
- Dark Keywords
- Dart Variable
- Data Type
- Dart Operators
- Dart List
- Dart Set
- Dart Map
- if else + Nested
- Dart Wsitch
- Dart For Loop
- Dart while and do while
- Dart Function
- Dart OOP
- Class
- Object
- Inheritance
- Polymorphism
- Interface
- Abstract class
OOP Concept :
Source code Flow
My App -> MaterialApp -> Activity -> Scaffold (appBar,body)
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: HomeActivity(),
);
}
}
class HomeActivity extends StatelessWidget {
const HomeActivity({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('My App'),
backgroundColor: Colors.blue,
),
body: Center(
child: Text('Home'),
),
);
}
}
MaterialApp class
MaterialApp(
theme: ThemeData(primarySwatch: Colors.cyan),
darkTheme: ThemeData(primarySwatch: Colors.pink),
color: Colors.blue,
debugShowCheckedModeBanner: false,
home: HomeActivity(),
)
Scaffold class
Scaffold(
Appbar,
Drawer,
EndDrawer,
Floating Action Button,
Bottom tab navigation,
Body
)
AppBar
AppBar(
title: Text('My App'),
titleSpacing: 20,
centerTitle: true,
toolbarHeight: 60,
toolbarOpacity: 1,
elevation: 0,
backgroundColor: Colors.blue,
iconTheme: IconThemeData(color: Colors.white),
),
AppBar Action IconButton
AppBar(
actions: [
IconButton(onPressed: (){}, icon: Icon(Icons.search))
]
)
SnackBar
onPressed: (){ MysnackBar('Messege',context); }
MysnackBar(msg,context){
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(msg)));
}
Floating Button
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.blue,
child: Icon(Icons.add,color: Colors.white,),
onPressed: (){},
),
Drawer
drawer: Drawer(
child: ListView(
children: [
DrawerHeader(
padding: EdgeInsets.all(0),
child: UserAccountsDrawerHeader(
decoration: BoxDecoration(color: Colors.blue),
accountName: Text('Nahid'),
accountEmail: Text('nahid@gmail.com'),
onDetailsPressed: (){},
currentAccountPicture: Image.network('src'),
)),
ListTile(title: Text('Home'), leading: Icon(Icons.home), onTap: (){},),
ListTile(title: Text('Card'), leading: Icon(Icons.card_giftcard), onTap: (){},),
ListTile(title: Text('File'), leading: Icon(Icons.file_copy), onTap: (){},),
ListTile(title: Text('Setting'), leading: Icon(Icons.settings_outlined), onTap: (){},),
ListTile(title: Text('About'), leading: Icon(Icons.account_circle), onTap: (){},),
],
),
)
End Drawer
endDrawer : Drawer(
child: ListView(
children: [
DrawerHeader(
padding: EdgeInsets.all(0),
child: UserAccountsDrawerHeader(
decoration: BoxDecoration(color: Colors.blue),
accountName: Text('Nahid'),
accountEmail: Text('nahid@gmail.com'),
onDetailsPressed: (){},
currentAccountPicture: Image.network('src'),
)),
ListTile(title: Text('Home'), leading: Icon(Icons.home), onTap: (){},),
ListTile(title: Text('Card'), leading: Icon(Icons.card_giftcard), onTap: (){},),
ListTile(title: Text('File'), leading: Icon(Icons.file_copy), onTap: (){},),
ListTile(title: Text('Setting'), leading: Icon(Icons.settings_outlined), onTap: (){},),
ListTile(title: Text('About'), leading: Icon(Icons.account_circle), onTap: (){},),
],
),
)
Body & Container
body: Center(
child: Container(
width: 200,
height: 200,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.blue,
border: Border.all(color: Colors.black,width: 1),
borderRadius: BorderRadius.all(Radius.circular(10)),
boxShadow: [
BoxShadow(
color: Colors.black87,
blurRadius: 30
)
]
),
child: Text('Nahid'),
),
)
Row & Column
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('1'),
Text('2'),
Text('3'),
Text('4'),
Text('5'),
],
)
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('1'),
Text('2'),
Text('3'),
Text('4'),
Text('5'),
],
)
Alert Dialog
alertbox(
{String? title,
String? bodytext,
required BuildContext? context,
required VoidCallback? yesOnpress,
required VoidCallback? noOnpress,
})
{
/// Main Code
showDialog(
context: context!,
builder: (BuildContext context){
return (
Expanded(
child: AlertDialog(
title: Text('$title'),
content: Text('$bodytext'),
actions: [
OutlinedButton(onPressed: noOnpress, child: Text('No')),
ElevatedButton(onPressed: yesOnpress, child: Text('Yes')),
],
),
)
);
});
/// main code
}
ElevatedButton(onPressed: (){
alertbox(
title: 'Nahid',
bodytext: 'hi i am Nahid',
context: context,
yesOnpress: (){},
noOnpress: (){
Navigator.of(context).pop();
});
}, child: Text('Click'))
TextField
var username = TextEditingController();
TextField(
controller: username,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'UserName'
),
)