Unit 2 Flutter Part 2
Unit 2 Flutter Part 2
const MaterialApp(
{
Key key,
GlobalKey<NavigatorState> navigatorKey,
Widget home,
String initialRoute,
RouteFactory onGenerateRoute,
InitialRouteListFactory onGenerateInitialRoutes,
RouteFactory onUnknownRoute,
TransitionBuilder builder,
GenerateAppTitle onGenerateTitle,
Color color,
ThemeData theme,
ThemeData darkTheme,
ThemeData highContrastTheme,
ThemeData highContrastDarkTheme,
Locale locale,
Iterable<LocalizationsDelegate> localizationsDelegates,
LocaleListResolutionCallback localeListResolutionCallback,
LocaleResolutionCallback localeResolutionCallback,
Property Description
navigator.
This property
holds List<NavigatorObserver> as the object
navigatorObserver to create a list of observers for the navigator.
This property
holds RouteInformationParser<T> as the
object to the routing information from the
routeInformationProvider into a generic
routeInformationParse data type.
In order to use the app drawer you need to import the material component package that is ”
package: flutter/material.dart.”
The Navigating AppDrawer is divided into three sections namely header, body, and footer.
The idea is about having a navigator with a couple of items as the drawer’s child that will be
navigated to different destinations on getting tapped. All children of a Drawer widget are
usually in ListView and initially, only the DrawerHeader is present in the UI which when
tapped extends horizontally.
Constructors:
Syntax:
Properties:
elevation: The z-coordinate at which to place this drawer relative to its parent.
Important Function:
build(BuildContext context) → Widget: This method specifies the part of the UI rendered by
the widget. This method is called when the Drawer widget is inserted into the tree in a given
BuildContext and when the dependencies of the Drawer widget change.
Implementation:
@override
assert(debugCheckHasMaterialLocalizations(context));
switch (Theme.of(context).platform) {
case TargetPlatform.iOS:
case TargetPlatform.macOS:
break;
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.linux:
case TargetPlatform.windows:
return Semantics(
scopesRoute: true,
namesRoute: true,
explicitChildNodes: true,
label: label,
child: ConstrainedBox(
child: Material(
elevation: elevation,
child: child,
),
),
);
Why Drawers?
Drawers are very easy to implement as well as handy to balance different functionalities of
your mobile application at the same time. Creating a drawer makes visiting different
destinations in your app quite easy and manageable to a large extent, especially in the case
of a complex application with many screens.
You can easily switch between different screens and perform tasks.
1. Create a flutter project: Open the terminal and navigate to the desired location in which
you want to create your project. Using the “flutter create project_name” command creates
your flutter project.
2. Create a scaffold widget: Inside the MyApp Class of your stateless/stateful widget return a
scaffold widget. A Scaffold Widget provides a framework for implementing the basic visual
layout structure of the flutter app.
Scaffold(
drawer:
);
3. Add Drawer inside the scaffold: Set the scaffold’s drawer property to Drawer with
ListView as its child or you can add a Container with a ListView as its child as well. Various
ListViews contain desired items that needed to be displayed inside the drawer.
Scaffold(
drawer: Drawer(
//...
),);
4. Add a closing functionality: Navigator is used for implementing closing functionality on the
drawer when the user wants to close it after tapping on some item. This can be done using a
Navigator State.
Navigator.of(context).pop();
1. Standard Navigation Drawer: They provide user interaction with the screen content and
drawer at the same time.
2. Modal Navigation Drawer: These drawers block the user interaction with the rest of the
screen and allow only the user to interact with the drawer only.
3. Bottom Navigation Drawer: These are similar to modal navigation drawers except the
orientation of the drawer is towards the bottom section of the screen.