Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
03f92106
Commit
03f92106
authored
Apr 22, 2016
by
Hans Muller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored MaterialApp (#3475)
* Refactored MaterialApp
parent
a6532cc7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
49 deletions
+82
-49
app.dart
packages/flutter/lib/src/material/app.dart
+77
-46
app.dart
packages/flutter/lib/src/widgets/app.dart
+5
-3
No files found.
packages/flutter/lib/src/material/app.dart
View file @
03f92106
...
...
@@ -25,68 +25,45 @@ const TextStyle _errorTextStyle = const TextStyle(
/// An application that uses material design.
///
/// A convenience widget that wraps a number of widgets that are commonly
/// required for material design applications. It builds upon
/// required for material design applications. It builds upon
a
/// [WidgetsApp] by adding material-design specific functionality, such as
/// [AnimatedTheme] and [GridPaper]. This widget also configures the top-level
/// [Navigator] to perform [Hero] animations.
/// [Navigator]
's observer
to perform [Hero] animations.
///
/// See also:
///
/// * [WidgetsApp]
/// * [Scaffold]
/// * [MaterialPageRoute]
class
MaterialApp
extends
WidgetsApp
{
class
MaterialApp
extends
StatefulWidget
{
/// Creates a MaterialApp.
///
/// At least one of [home], [routes], or [onGenerateRoute] must be
/// given. If only [routes] is given, it must include an entry for
/// the [Navigator.defaultRouteName] (`'/'`).
///
///
See also the [new WidgetsApp] constructor (which this extends)
.
///
This class creates an instance of [WidgetsApp]
.
MaterialApp
({
Key
key
,
String
title
,
ThemeData
theme
,
Widget
home
,
Map
<
String
,
WidgetBuilder
>
routes:
const
<
String
,
WidgetBuilder
>{},
RouteFactory
onGenerateRoute
,
LocaleChangedCallback
onLocaleChanged
,
this
.
title
,
this
.
theme
,
this
.
home
,
this
.
routes
:
const
<
String
,
WidgetBuilder
>{},
this
.
onGenerateRoute
,
this
.
onLocaleChanged
,
this
.
debugShowMaterialGrid
:
false
,
bool
showPerformanceOverlay:
false
,
bool
showSemanticsDebugger:
false
,
bool
debugShowCheckedModeBanner:
true
})
:
theme
=
theme
,
home
=
home
,
routes
=
routes
,
super
(
key:
key
,
title:
title
,
textStyle:
_errorTextStyle
,
color:
theme
?.
primaryColor
??
Colors
.
blue
[
500
],
// blue[500] is the primary color of the default theme
onGenerateRoute:
(
RouteSettings
settings
)
{
WidgetBuilder
builder
=
routes
[
settings
.
name
];
if
(
builder
==
null
&&
home
!=
null
&&
settings
.
name
==
Navigator
.
defaultRouteName
)
builder
=
(
BuildContext
context
)
=>
home
;
if
(
builder
!=
null
)
{
return
new
MaterialPageRoute
<
Null
>(
builder:
builder
,
settings:
settings
);
}
if
(
onGenerateRoute
!=
null
)
return
onGenerateRoute
(
settings
);
return
null
;
},
onLocaleChanged:
onLocaleChanged
,
showPerformanceOverlay:
showPerformanceOverlay
,
showSemanticsDebugger:
showSemanticsDebugger
,
debugShowCheckedModeBanner:
debugShowCheckedModeBanner
)
{
this
.
showPerformanceOverlay
:
false
,
this
.
showSemanticsDebugger
:
false
,
this
.
debugShowCheckedModeBanner
:
true
})
:
super
(
key:
key
)
{
assert
(
debugShowMaterialGrid
!=
null
);
assert
(
routes
!=
null
);
assert
(!
routes
.
containsKey
(
Navigator
.
defaultRouteName
)
||
(
home
==
null
));
assert
(
routes
.
containsKey
(
Navigator
.
defaultRouteName
)
||
(
home
!=
null
)
||
(
onGenerateRoute
!=
null
));
}
}
/// A one-line description of this app for use in the window manager.
final
String
title
;
/// The colors to use for the application's widgets.
final
ThemeData
theme
;
...
...
@@ -124,6 +101,37 @@ class MaterialApp extends WidgetsApp {
/// build the page instead.
final
Map
<
String
,
WidgetBuilder
>
routes
;
/// The route generator callback used when the app is navigated to a
/// named route.
final
RouteFactory
onGenerateRoute
;
/// Callback that is invoked when the operating system changes the
/// current locale.
final
LocaleChangedCallback
onLocaleChanged
;
/// Turns on a performance overlay.
/// https://flutter.io/debugging/#performanceoverlay
final
bool
showPerformanceOverlay
;
/// Turns on an overlay that shows the accessibility information
/// reported by the framework.
final
bool
showSemanticsDebugger
;
/// Turns on a little "SLOW MODE" banner in checked mode to indicate
/// that the app is in checked mode. This is on by default (in
/// checked mode), to turn it off, set the constructor argument to
/// false. In release mode this has no effect.
///
/// To get this banner in your application if you're not using
/// WidgetsApp, include a [CheckedModeBanner] widget in your app.
///
/// This banner is intended to deter people from complaining that your
/// app is slow when it's in checked mode. In checked mode, Flutter
/// enables a large number of expensive diagnostics to aid in
/// development, and so performance in checked mode is not
/// representative of what will happen in release mode.
final
bool
debugShowCheckedModeBanner
;
/// Turns on a [GridPaper] overlay that paints a baseline grid
/// Material apps:
/// https://www.google.com/design/spec/layout/metrics-keylines.html
...
...
@@ -134,11 +142,23 @@ class MaterialApp extends WidgetsApp {
_MaterialAppState
createState
()
=>
new
_MaterialAppState
();
}
class
_MaterialAppState
extends
WidgetsApp
State
<
MaterialApp
>
{
class
_MaterialAppState
extends
State
<
MaterialApp
>
{
final
HeroController
_heroController
=
new
HeroController
();
@override
NavigatorObserver
get
navigatorObserver
=>
_heroController
;
Route
<
dynamic
>
_onGenerateRoute
(
RouteSettings
settings
)
{
WidgetBuilder
builder
=
config
.
routes
[
settings
.
name
];
if
(
builder
==
null
&&
config
.
home
!=
null
&&
settings
.
name
==
Navigator
.
defaultRouteName
)
builder
=
(
BuildContext
context
)
=>
config
.
home
;
if
(
builder
!=
null
)
{
return
new
MaterialPageRoute
<
Null
>(
builder:
builder
,
settings:
settings
);
}
if
(
config
.
onGenerateRoute
!=
null
)
return
config
.
onGenerateRoute
(
settings
);
return
null
;
}
@override
Widget
build
(
BuildContext
context
)
{
...
...
@@ -146,8 +166,19 @@ class _MaterialAppState extends WidgetsAppState<MaterialApp> {
Widget
result
=
new
AnimatedTheme
(
data:
theme
,
duration:
kThemeAnimationDuration
,
child:
super
.
build
(
context
)
child:
new
WidgetsApp
(
title:
config
.
title
,
textStyle:
_errorTextStyle
,
color:
theme
?.
primaryColor
??
Colors
.
blue
[
500
],
// blue[500] is the primary color of the default theme
navigatorObserver:
_heroController
,
onGenerateRoute:
_onGenerateRoute
,
onLocaleChanged:
config
.
onLocaleChanged
,
showPerformanceOverlay:
config
.
showPerformanceOverlay
,
showSemanticsDebugger:
config
.
showSemanticsDebugger
,
debugShowCheckedModeBanner:
config
.
debugShowCheckedModeBanner
)
);
assert
(()
{
if
(
config
.
debugShowMaterialGrid
)
{
result
=
new
GridPaper
(
...
...
@@ -160,7 +191,7 @@ class _MaterialAppState extends WidgetsAppState<MaterialApp> {
}
return
true
;
});
return
result
;
}
}
packages/flutter/lib/src/widgets/app.dart
View file @
03f92106
...
...
@@ -37,6 +37,7 @@ class WidgetsApp extends StatefulWidget {
this
.
title
,
this
.
textStyle
,
this
.
color
,
this
.
navigatorObserver
,
this
.
onGenerateRoute
,
this
.
onLocaleChanged
,
this
.
showPerformanceOverlay
:
false
,
...
...
@@ -92,6 +93,9 @@ class WidgetsApp extends StatefulWidget {
/// representative of what will happen in release mode.
final
bool
debugShowCheckedModeBanner
;
/// The observer for the Navigator created for this app.
final
NavigatorObserver
navigatorObserver
;
static
bool
showPerformanceOverlayOverride
=
false
;
@override
...
...
@@ -151,8 +155,6 @@ class WidgetsAppState<T extends WidgetsApp> extends State<T> implements WidgetsB
@override
void
didChangeAppLifecycleState
(
AppLifecycleState
state
)
{
}
NavigatorObserver
get
navigatorObserver
=>
null
;
@override
Widget
build
(
BuildContext
context
)
{
if
(
config
.
onLocaleChanged
!=
null
&&
_localeData
==
null
)
{
...
...
@@ -176,7 +178,7 @@ class WidgetsAppState<T extends WidgetsApp> extends State<T> implements WidgetsB
key:
_navigator
,
initialRoute:
ui
.
window
.
defaultRouteName
,
onGenerateRoute:
config
.
onGenerateRoute
,
observer:
navigatorObserver
observer:
config
.
navigatorObserver
)
)
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment