You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. Close Top Stack Widget (Eg. Bottom Sheet, Dialog, etc.)
Navigator.of(context).pop();
//In StatefulWidget => State Class context is like widget flutter defined object we can use it without defining
2. Theme
//set theme of appMaterialApp(
theme:ThemeData(
primarySwatch :Colors.blue,
accentColor :Colors.yellow,
),
);
//To access theme dataTheme.of(context).primaryColor;
//Copy current theme data and overide with new styleMaterialApp(
theme :ThemeData(
appBarTheme :AppBarTheme(
textTheme:ThemeData.light().textTheme.copyWith(
title:TextStyle(
fontFamily :'OpenSans',
fontSize :20
)
)
)
),
);
3. Add Assets
#Add Imagesassets:
- assets/images/waiting.png#To Access the Image -> Image.asset("assets/images/waiting.png")# Add Fontsfonts:
- family: OpenSansfonts:
- asset: assets/fonts/OpenSans-Regular.ttf
- asset: assets/fonts/OpenSans-Bold.ttfweight: 700
- family: Quicksandfonts:
- asset: assets/fonts/Quicksand-Regular.ttf
- asset: assets/fonts/Quicksand-Bold.ttfweight: 700#defines weight after Bold font to Enable that particular font When use the Bold property in TextStyle
4. Flexible
//Uses All the available spaceFlexible(
flex :2, //Like CSS flex
fit :FlexFit.tight
)
//Alternatively use Expandable Expandable(
flex :2
)
5. Routes
//pushNavigator.of(context).push(
MaterialPageRoute(
builder:(_){
returnPage2Screen();
}
);
)
//pushNamed//1. Define routes in -> MaterialApp main.dartMaterialApp(
routes:{
'/': (_) =>HomePage(), // '/' is initialRoute so no need to mention home seperately if add this'/about': (_) =>AboutPage(),
'/product-details': (_) =>ProductDetailsPage(),
}
)
//2. Call named route
onTap:(){
Navigator.of(context).pushNamed(
'/product-details',
arguments:{
'id':id,
title:title
}
)
}
//3. Receive Arguments in ProductDetailsPage build methodWidgetbuild(BuildContext context) {
final routeArgs =ModelRoute.of(context).settings.arguments asMap<String,String>;
final id = routeArgs['id'];
final title = routeArgs['title'];
}
Media Query (Responsive Design)
var width =MediaQuery.of(context).size.width;
var height =MediaQuery.of(context).size.height;
//Height 60% var heightInPercentage =MediaQuery.of(context).size.height *0.6;
//Get Widget Size (Store it in variable) var appBarHeight = appBar.preferredSize.height;
//To Get Accurate Percentage Size remove appBar and Status Bar Height if includedvar heightIn60Percentage = (MediaQuery.of(context).size.height - appBar.preferredSize.height -MediaQuery.of(context).padding.top) *0.6;
SystemChrome
Portrait Mode Only
//In main functionSystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown
]);