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
4fa5fe5f
Unverified
Commit
4fa5fe5f
authored
Oct 29, 2020
by
Greg Spencer
Committed by
GitHub
Oct 29, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove nullOk from Scaffold.of and ScaffoldMessenger.of, create maybeOf for both (#68908)
parent
e5f7726c
Changes
8
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
105 additions
and
68 deletions
+105
-68
app_bar.dart
packages/flutter/lib/src/material/app_bar.dart
+3
-3
bottom_sheet.dart
packages/flutter/lib/src/material/bottom_sheet.dart
+1
-1
scaffold.dart
packages/flutter/lib/src/material/scaffold.dart
+48
-11
snack_bar.dart
packages/flutter/lib/src/material/snack_bar.dart
+3
-3
floating_action_button_location_test.dart
...r/test/material/floating_action_button_location_test.dart
+1
-1
scaffold_test.dart
packages/flutter/test/material/scaffold_test.dart
+5
-5
snack_bar_test.dart
packages/flutter/test/material/snack_bar_test.dart
+39
-39
snack_bar_theme_test.dart
packages/flutter/test/material/snack_bar_theme_test.dart
+5
-5
No files found.
packages/flutter/lib/src/material/app_bar.dart
View file @
4fa5fe5f
...
...
@@ -487,11 +487,11 @@ class _AppBarState extends State<AppBar> {
static
const
Color
_defaultShadowColor
=
Color
(
0xFF000000
);
void
_handleDrawerButton
()
{
Scaffold
.
of
(
context
)
!
.
openDrawer
();
Scaffold
.
of
(
context
).
openDrawer
();
}
void
_handleDrawerButtonEnd
()
{
Scaffold
.
of
(
context
)
!
.
openEndDrawer
();
Scaffold
.
of
(
context
).
openEndDrawer
();
}
@override
...
...
@@ -500,7 +500,7 @@ class _AppBarState extends State<AppBar> {
assert
(
debugCheckHasMaterialLocalizations
(
context
));
final
ThemeData
?
theme
=
Theme
.
of
(
context
);
final
AppBarTheme
appBarTheme
=
AppBarTheme
.
of
(
context
);
final
ScaffoldState
?
scaffold
=
Scaffold
.
of
(
context
,
nullOk:
true
);
final
ScaffoldState
?
scaffold
=
Scaffold
.
maybeOf
(
context
);
final
ModalRoute
<
dynamic
>?
parentRoute
=
ModalRoute
.
of
(
context
);
final
bool
hasDrawer
=
scaffold
?.
hasDrawer
??
false
;
...
...
packages/flutter/lib/src/material/bottom_sheet.dart
View file @
4fa5fe5f
...
...
@@ -737,7 +737,7 @@ PersistentBottomSheetController<T> showBottomSheet<T>({
assert
(
builder
!=
null
);
assert
(
debugCheckHasScaffold
(
context
));
return
Scaffold
.
of
(
context
)
!
.
showBottomSheet
<
T
>(
return
Scaffold
.
of
(
context
).
showBottomSheet
<
T
>(
builder
,
backgroundColor:
backgroundColor
,
elevation:
elevation
,
...
...
packages/flutter/lib/src/material/scaffold.dart
View file @
4fa5fe5f
...
...
@@ -204,16 +204,34 @@ class ScaffoldMessenger extends StatefulWidget {
/// ```
/// {@end-tool}
///
/// If there is no [ScaffoldMessenger] in scope, then this will return null.
/// If there is no [ScaffoldMessenger] in scope, then this will assert in
/// debug mode, and throw an exception in release mode.
///
/// See also:
///
/// * [maybeOf], which is a similar function but will return null instead of
/// throwing if there is no [ScaffoldMessenger] ancestor.
/// * [debugCheckHasScaffoldMessenger], which asserts that the given context
/// has a [ScaffoldMessenger] ancestor.
static
ScaffoldMessengerState
?
of
(
BuildContext
context
,
{
bool
nullOk
=
false
})
{
assert
(
nullOk
!=
null
);
static
ScaffoldMessengerState
of
(
BuildContext
context
)
{
assert
(
context
!=
null
);
assert
(
debugCheckHasScaffoldMessenger
(
context
));
assert
(
nullOk
||
debugCheckHasScaffoldMessenger
(
context
));
final
_ScaffoldMessengerScope
scope
=
context
.
dependOnInheritedWidgetOfExactType
<
_ScaffoldMessengerScope
>()!;
return
scope
.
_scaffoldMessengerState
;
}
/// The state from the closest instance of this class that encloses the given
/// context, if any.
///
/// Will return null if a [ScaffoldMessenger] is not found in the given context.
///
/// See also:
///
/// * [of], which is a similar function, except that it will throw an
/// exception if a [ScaffoldMessenger] is not found in the given context.
static
ScaffoldMessengerState
?
maybeOf
(
BuildContext
context
)
{
assert
(
context
!=
null
);
final
_ScaffoldMessengerScope
?
scope
=
context
.
dependOnInheritedWidgetOfExactType
<
_ScaffoldMessengerScope
>();
return
scope
?.
_scaffoldMessengerState
;
...
...
@@ -1755,7 +1773,11 @@ class Scaffold extends StatefulWidget {
/// By default, the drag gesture is enabled.
final
bool
endDrawerEnableOpenDragGesture
;
/// The state from the closest instance of this class that encloses the given context.
/// Finds the [ScaffoldState] from the closest instance of this class that
/// encloses the given context.
///
/// If no instance of this class encloses the given context, will cause an
/// assert in debug mode, and throw an exception in release mode.
///
/// {@tool dartpad --template=freeform}
/// Typical usage of the [Scaffold.of] function is to call it from within the
...
...
@@ -1892,12 +1914,11 @@ class Scaffold extends StatefulWidget {
/// [ScaffoldState] rather than using the [Scaffold.of] function.
///
/// If there is no [Scaffold] in scope, then this will throw an exception.
/// To return null if there is no [Scaffold], then pass `nullOk: true`.
static
ScaffoldState
?
of
(
BuildContext
context
,
{
bool
nullOk
=
false
})
{
assert
(
nullOk
!=
null
);
/// To return null if there is no [Scaffold], use [maybeOf] instead.
static
ScaffoldState
of
(
BuildContext
context
)
{
assert
(
context
!=
null
);
final
ScaffoldState
?
result
=
context
.
findAncestorStateOfType
<
ScaffoldState
>();
if
(
nullOk
||
result
!=
null
)
if
(
result
!=
null
)
return
result
;
throw
FlutterError
.
fromParts
(<
DiagnosticsNode
>[
ErrorSummary
(
...
...
@@ -1927,6 +1948,22 @@ class Scaffold extends StatefulWidget {
]);
}
/// Finds the [ScaffoldState] from the closest instance of this class that
/// encloses the given context.
///
/// If no instance of this class encloses the given context, will return null.
/// To throw an exception instead, use [of] instead of this function.
///
/// See also:
///
/// * [of], a similar function to this one that throws if no instance
/// encloses the given context. Also includes some sample code in its
/// documentation.
static
ScaffoldState
?
maybeOf
(
BuildContext
context
)
{
assert
(
context
!=
null
);
return
context
.
findAncestorStateOfType
<
ScaffoldState
>();
}
/// Returns a [ValueListenable] for the [ScaffoldGeometry] for the closest
/// [Scaffold] ancestor of the given context.
///
...
...
@@ -2714,7 +2751,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
void
didChangeDependencies
()
{
// nullOk is valid here since both the Scaffold and ScaffoldMessenger are
// currently available for managing SnackBars.
final
ScaffoldMessengerState
?
_currentScaffoldMessenger
=
ScaffoldMessenger
.
of
(
context
,
nullOk:
true
);
final
ScaffoldMessengerState
?
_currentScaffoldMessenger
=
ScaffoldMessenger
.
maybeOf
(
context
);
// If our ScaffoldMessenger has changed, unregister with the old one first.
if
(
_scaffoldMessenger
!=
null
&&
(
_currentScaffoldMessenger
==
null
||
_scaffoldMessenger
!=
_currentScaffoldMessenger
))
{
...
...
@@ -3304,7 +3341,7 @@ class _StandardBottomSheetState extends State<_StandardBottomSheet> {
bool
extentChanged
(
DraggableScrollableNotification
notification
)
{
final
double
extentRemaining
=
1.0
-
notification
.
extent
;
final
ScaffoldState
scaffold
=
Scaffold
.
of
(
context
)
!
;
final
ScaffoldState
scaffold
=
Scaffold
.
of
(
context
);
if
(
extentRemaining
<
_kBottomSheetDominatesPercentage
)
{
scaffold
.
_floatingActionButtonVisibilityValue
=
extentRemaining
*
_kBottomSheetDominatesPercentage
*
10
;
scaffold
.
showBodyScrim
(
true
,
math
.
max
(
...
...
packages/flutter/lib/src/material/snack_bar.dart
View file @
4fa5fe5f
...
...
@@ -123,7 +123,7 @@ class _SnackBarActionState extends State<SnackBarAction> {
_haveTriggeredAction
=
true
;
});
widget
.
onPressed
();
Scaffold
.
of
(
context
)
!
.
hideCurrentSnackBar
(
reason:
SnackBarClosedReason
.
action
);
Scaffold
.
of
(
context
).
hideCurrentSnackBar
(
reason:
SnackBarClosedReason
.
action
);
}
@override
...
...
@@ -529,14 +529,14 @@ class _SnackBarState extends State<SnackBar> {
container:
true
,
liveRegion:
true
,
onDismiss:
()
{
Scaffold
.
of
(
context
)
!
.
removeCurrentSnackBar
(
reason:
SnackBarClosedReason
.
dismiss
);
Scaffold
.
of
(
context
).
removeCurrentSnackBar
(
reason:
SnackBarClosedReason
.
dismiss
);
},
child:
Dismissible
(
key:
const
Key
(
'dismissible'
),
direction:
DismissDirection
.
down
,
resizeDuration:
null
,
onDismissed:
(
DismissDirection
direction
)
{
Scaffold
.
of
(
context
)
!
.
removeCurrentSnackBar
(
reason:
SnackBarClosedReason
.
swipe
);
Scaffold
.
of
(
context
).
removeCurrentSnackBar
(
reason:
SnackBarClosedReason
.
swipe
);
},
child:
snackBar
,
),
...
...
packages/flutter/test/material/floating_action_button_location_test.dart
View file @
4fa5fe5f
...
...
@@ -647,7 +647,7 @@ void main() {
builder:
(
BuildContext
context
)
{
return
FloatingActionButton
(
onPressed:
()
{
ScaffoldMessenger
.
of
(
context
)
!
.
showSnackBar
(
ScaffoldMessenger
.
of
(
context
).
showSnackBar
(
const
SnackBar
(
content:
Text
(
'Snacky!'
)),
);
},
...
...
packages/flutter/test/material/scaffold_test.dart
View file @
4fa5fe5f
...
...
@@ -355,7 +355,7 @@ void main() {
builder:
(
BuildContext
context
)
{
return
GestureDetector
(
onTap:
()
{
Scaffold
.
of
(
context
)
!
.
showBottomSheet
<
void
>((
BuildContext
context
)
{
Scaffold
.
of
(
context
).
showBottomSheet
<
void
>((
BuildContext
context
)
{
return
Container
(
key:
sheetKey
,
color:
Colors
.
blue
[
500
],
...
...
@@ -1900,7 +1900,7 @@ void main() {
MaterialApp
(
home:
Builder
(
builder:
(
BuildContext
context
)
{
Scaffold
.
of
(
context
)
!
.
showBottomSheet
<
void
>((
BuildContext
context
)
{
Scaffold
.
of
(
context
).
showBottomSheet
<
void
>((
BuildContext
context
)
{
return
Container
();
});
return
Container
();
...
...
@@ -2033,7 +2033,7 @@ void main() {
});
});
testWidgets
(
'ScaffoldMessenger.
of can return null
'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'ScaffoldMessenger.
maybeOf can return null if not found
'
,
(
WidgetTester
tester
)
async
{
ScaffoldMessengerState
?
scaffoldMessenger
;
const
Key
tapTarget
=
Key
(
'tap-target'
);
await
tester
.
pumpWidget
(
Directionality
(
...
...
@@ -2045,7 +2045,7 @@ void main() {
builder:
(
BuildContext
context
)
{
return
GestureDetector
(
onTap:
()
{
scaffoldMessenger
=
ScaffoldMessenger
.
of
(
context
,
nullOk:
true
);
scaffoldMessenger
=
ScaffoldMessenger
.
maybeOf
(
context
);
},
behavior:
HitTestBehavior
.
opaque
,
child:
Container
(
...
...
@@ -2064,7 +2064,7 @@ void main() {
expect
(
scaffoldMessenger
,
isNull
);
});
testWidgets
(
'ScaffoldMessenger.of will assert if
!nullOk
'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'ScaffoldMessenger.of will assert if
not found
'
,
(
WidgetTester
tester
)
async
{
const
Key
tapTarget
=
Key
(
'tap-target'
);
final
List
<
dynamic
>
exceptions
=
<
dynamic
>[];
...
...
packages/flutter/test/material/snack_bar_test.dart
View file @
4fa5fe5f
This diff is collapsed.
Click to expand it.
packages/flutter/test/material/snack_bar_theme_test.dart
View file @
4fa5fe5f
...
...
@@ -71,7 +71,7 @@ void main() {
builder:
(
BuildContext
context
)
{
return
GestureDetector
(
onTap:
()
{
ScaffoldMessenger
.
of
(
context
)
!
.
showSnackBar
(
SnackBar
(
ScaffoldMessenger
.
of
(
context
).
showSnackBar
(
SnackBar
(
content:
const
Text
(
text
),
duration:
const
Duration
(
seconds:
2
),
action:
SnackBarAction
(
label:
'ACTION'
,
onPressed:
()
{}),
...
...
@@ -109,7 +109,7 @@ void main() {
builder:
(
BuildContext
context
)
{
return
GestureDetector
(
onTap:
()
{
ScaffoldMessenger
.
of
(
context
)
!
.
showSnackBar
(
SnackBar
(
ScaffoldMessenger
.
of
(
context
).
showSnackBar
(
SnackBar
(
content:
const
Text
(
text
),
duration:
const
Duration
(
seconds:
2
),
action:
SnackBarAction
(
label:
action
,
onPressed:
()
{}),
...
...
@@ -153,7 +153,7 @@ void main() {
builder:
(
BuildContext
context
)
{
return
GestureDetector
(
onTap:
()
{
ScaffoldMessenger
.
of
(
context
)
!
.
showSnackBar
(
SnackBar
(
ScaffoldMessenger
.
of
(
context
).
showSnackBar
(
SnackBar
(
backgroundColor:
backgroundColor
,
elevation:
elevation
,
shape:
shape
,
...
...
@@ -200,7 +200,7 @@ void main() {
builder:
(
BuildContext
context
)
{
return
GestureDetector
(
onTap:
()
{
ScaffoldMessenger
.
of
(
context
)
!
.
showSnackBar
(
SnackBar
(
ScaffoldMessenger
.
of
(
context
).
showSnackBar
(
SnackBar
(
content:
const
Text
(
'I am a snack bar.'
),
duration:
const
Duration
(
seconds:
2
),
action:
SnackBarAction
(
label:
'ACTION'
,
onPressed:
()
{}),
...
...
@@ -242,7 +242,7 @@ void main() {
builder:
(
BuildContext
context
)
{
return
GestureDetector
(
onTap:
()
{
ScaffoldMessenger
.
of
(
context
)
!
.
showSnackBar
(
SnackBar
(
ScaffoldMessenger
.
of
(
context
).
showSnackBar
(
SnackBar
(
content:
const
Text
(
'I am a snack bar.'
),
duration:
const
Duration
(
seconds:
2
),
action:
SnackBarAction
(
label:
'ACTION'
,
onPressed:
()
{}),
...
...
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