Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null safety fixes - making animationController getter non-nullable #87

Merged
merged 3 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include: package:pedantic/analysis_options.1.8.0.yaml
include: package:pedantic/analysis_options.yaml

analyzer:
exclude: [build/**]
Expand Down
2 changes: 1 addition & 1 deletion lib/app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class BackdropAppBar extends StatelessWidget implements PreferredSizeWidget {
assert(toolbarOpacity != null),
assert(bottomOpacity != null),
preferredSize = Size.fromHeight(
kToolbarHeight + (bottom?.preferredSize?.height ?? 0.0)),
kToolbarHeight + (bottom?.preferredSize.height ?? 0.0)),
super(key: key);

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class BackdropToggleButton extends StatelessWidget {
icon: AnimatedIcon(
icon: icon,
color: color,
progress: Backdrop.of(context).animationController!.view,
progress: Backdrop.of(context).animationController.view,
),
onPressed: () => Backdrop.of(context).fling(),
);
Expand Down
76 changes: 47 additions & 29 deletions lib/scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';

@Deprecated('Replace with frontLayerScrim.')
const _kInactiveOverlayOpacity = 0.7;
@Deprecated('Replace with frontLayerScrim.')
const _kInactiveOverlayColor = Color(0xFFEEEEEE);

/// This class is an InheritedWidget that exposes state of [BackdropScaffold]
/// [BackdropScaffoldState] to be accessed from anywhere below the widget tree.
///
Expand Down Expand Up @@ -181,12 +186,12 @@ class BackdropScaffold extends StatefulWidget {

/// Deprecated. Use [frontLayerScrim] instead.
@Deprecated('Replace with frontLayerScrim.')
final Color inactiveOverlayColor;
final Color? inactiveOverlayColor;

/// Deprecated. Use [frontLayerScrim] instead.
@Deprecated('Replace with frontLayerScrim. Use Color#withOpacity, or pass'
'the opacity value in the Color constructor.')
final double inactiveOverlayOpacity;
final double? inactiveOverlayOpacity;

/// Defines the scrim color for the front layer when minimized
/// (revealing the back layer) and animating. Defaults to [Colors.white70].
Expand Down Expand Up @@ -315,9 +320,9 @@ class BackdropScaffold extends StatefulWidget {
double frontLayerActiveFactor = 1,
this.backLayerBackgroundColor,
@Deprecated('See frontLayerScrim. This was deprecated after v0.4.7.')
this.inactiveOverlayColor = const Color(0xFFEEEEEE),
this.inactiveOverlayColor,
@Deprecated('See frontLayerScrim. This was deprecated after v0.4.7.')
this.inactiveOverlayOpacity = 0.7,
this.inactiveOverlayOpacity,
this.frontLayerScrim = Colors.white70,
this.backLayerScrim = Colors.black54,
this.onBackLayerConcealed,
Expand All @@ -342,7 +347,8 @@ class BackdropScaffold extends StatefulWidget {
this.drawerEdgeDragWidth,
this.drawerEnableOpenDragGesture = true,
this.endDrawerEnableOpenDragGesture = true,
}) : assert(inactiveOverlayOpacity >= 0.0 && inactiveOverlayOpacity <= 1.0),
}) : assert(inactiveOverlayOpacity == null ||
inactiveOverlayOpacity >= 0.0 && inactiveOverlayOpacity <= 1.0),
frontLayerActiveFactor = frontLayerActiveFactor.clamp(0, 1).toDouble(),
super(key: key);

Expand All @@ -361,7 +367,7 @@ class BackdropScaffold extends StatefulWidget {
class BackdropScaffoldState extends State<BackdropScaffold>
with SingleTickerProviderStateMixin {
bool _shouldDisposeAnimationController = false;
AnimationController? _animationController;
late AnimationController _animationController;
late ColorTween _backLayerScrimColorTween;

/// Key for accessing the [ScaffoldState] of [BackdropScaffold]'s internally
Expand All @@ -375,7 +381,7 @@ class BackdropScaffoldState extends State<BackdropScaffold>
/// [AnimationController] used for the backdrop animation.
@Deprecated("Replace by the use of `animationController`."
"This feature was deprecated after v0.5.1.")
AnimationController? get controller => _animationController;
AnimationController get controller => _animationController;

/// [AnimationController] used for the backdrop animation.
///
Expand All @@ -384,7 +390,7 @@ class BackdropScaffoldState extends State<BackdropScaffold>
/// AnimationController(
/// vsync: this, duration: Duration(milliseconds: 200), value: 1)
/// ```
AnimationController? get animationController => _animationController;
AnimationController get animationController => _animationController;

@override
void initState() {
Expand All @@ -406,7 +412,7 @@ class BackdropScaffoldState extends State<BackdropScaffold>

_backLayerScrimColorTween = _buildBackLayerScrimColorTween();

_animationController!.addListener(() => setState(() {
_animationController.addListener(() => setState(() {
// This is intentionally left empty. The state change itself takes
// place inside the AnimationController, so there's nothing to update.
// All we want is for the widget to rebuild and read the new animation
Expand All @@ -425,7 +431,7 @@ class BackdropScaffoldState extends State<BackdropScaffold>

@override
void dispose() {
if (_shouldDisposeAnimationController) _animationController!.dispose();
if (_shouldDisposeAnimationController) _animationController.dispose();
super.dispose();
}

Expand All @@ -438,8 +444,8 @@ class BackdropScaffoldState extends State<BackdropScaffold>

/// Whether the back layer is concealed or not.
bool get isBackLayerConcealed =>
animationController!.status == AnimationStatus.completed ||
animationController!.status == AnimationStatus.forward;
animationController.status == AnimationStatus.completed ||
animationController.status == AnimationStatus.forward;

/// Deprecated. Use [isBackLayerRevealed] instead.
///
Expand All @@ -450,16 +456,16 @@ class BackdropScaffoldState extends State<BackdropScaffold>

/// Whether the back layer is revealed or not.
bool get isBackLayerRevealed =>
animationController!.status == AnimationStatus.dismissed ||
animationController!.status == AnimationStatus.reverse;
animationController.status == AnimationStatus.dismissed ||
animationController.status == AnimationStatus.reverse;

/// Toggles the backdrop functionality.
///
/// If the back layer was concealed, it is animated to the "revealed" state
/// by this function. If it was revealed, this function will animate it to
/// the "concealed" state.
void fling() {
FocusScope.of(context)?.unfocus();
FocusScope.of(context).unfocus();
if (isBackLayerConcealed) {
revealBackLayer();
} else {
Expand All @@ -477,7 +483,7 @@ class BackdropScaffoldState extends State<BackdropScaffold>
/// Animates the back layer to the "revealed" state.
void revealBackLayer() {
if (isBackLayerConcealed) {
animationController!.animateBack(-1);
animationController.animateBack(-1);
widget.onBackLayerRevealed?.call();
}
}
Expand All @@ -492,7 +498,7 @@ class BackdropScaffoldState extends State<BackdropScaffold>
/// Animates the back layer to the "concealed" state.
void concealBackLayer() {
if (isBackLayerRevealed) {
animationController!.animateTo(1);
animationController.animateTo(1);
widget.onBackLayerConcealed?.call();
}
}
Expand Down Expand Up @@ -526,17 +532,31 @@ class BackdropScaffoldState extends State<BackdropScaffold>
end: RelativeRect.fromLTRB(
0, availableHeight * (1 - widget.frontLayerActiveFactor), 0, 0),
).animate(CurvedAnimation(
parent: animationController!,
parent: animationController,
curve: widget.animationCurve,
reverseCurve:
widget.reverseAnimationCurve ?? widget.animationCurve.flipped));
}

Widget _buildInactiveLayer(BuildContext context) {
Color? frontLayerScrim;
if (widget.inactiveOverlayColor == null &&
widget.inactiveOverlayOpacity == null) {
frontLayerScrim = widget.frontLayerScrim;
} else if (widget.inactiveOverlayOpacity == null) {
frontLayerScrim = widget.inactiveOverlayColor!.withOpacity(
_kInactiveOverlayOpacity,
);
} else if (widget.inactiveOverlayColor == null) {
frontLayerScrim = _kInactiveOverlayColor.withOpacity(
widget.inactiveOverlayOpacity!,
);
}

return Offstage(
offstage: animationController!.status == AnimationStatus.completed,
offstage: animationController.status == AnimationStatus.completed,
child: FadeTransition(
opacity: Tween<double>(begin: 1, end: 0).animate(animationController!),
opacity: Tween<double>(begin: 1, end: 0).animate(animationController),
child: GestureDetector(
onTap: () => fling(),
behavior: HitTestBehavior.opaque,
Expand All @@ -548,9 +568,8 @@ class BackdropScaffoldState extends State<BackdropScaffold>
: Container(),
Expanded(
child: Container(
color: widget.frontLayerScrim ??
widget.inactiveOverlayColor
.withOpacity(widget.inactiveOverlayOpacity)),
color: frontLayerScrim,
),
),
],
),
Expand All @@ -576,7 +595,7 @@ class BackdropScaffoldState extends State<BackdropScaffold>
setState(() => _backPanelHeight = size.height);
}
},
child: widget.backLayer ?? Container(),
child: widget.backLayer,
),
),
],
Expand Down Expand Up @@ -624,10 +643,10 @@ class BackdropScaffoldState extends State<BackdropScaffold>
);
}

Future<bool?> _willPopCallback(BuildContext context) async {
Future<bool> _willPopCallback(BuildContext context) async {
if (isBackLayerRevealed) {
concealBackLayer();
return null;
return false;
}
return true;
}
Expand All @@ -639,8 +658,7 @@ class BackdropScaffoldState extends State<BackdropScaffold>

Widget _buildBody(BuildContext context) {
return WillPopScope(
onWillPop: (() => _willPopCallback(context) as Future<bool>)
as Future<bool> Function()?,
onWillPop: (() => _willPopCallback(context)),
child: Scaffold(
key: scaffoldKey,
appBar: widget.appBar ??
Expand Down Expand Up @@ -693,7 +711,7 @@ class BackdropScaffoldState extends State<BackdropScaffold>
}

Container _buildBackLayerScrim() => Container(
color: _backLayerScrimColorTween.evaluate(animationController!),
color: _backLayerScrimColorTween.evaluate(animationController),
height: _backPanelHeight);

bool get _hasBackLayerScrim =>
Expand Down
2 changes: 1 addition & 1 deletion lib/sub_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class BackdropSubHeader extends StatelessWidget {
Widget _buildAutomaticLeadingOrTrailing(BuildContext context) =>
FadeTransition(
opacity: Tween(begin: 1.0, end: 0.0)
.animate(Backdrop.of(context).animationController!),
.animate(Backdrop.of(context).animationController),
child: Icon(Icons.keyboard_arrow_up),
);

Expand Down