Matthieu Pernelle
Committed by GitHub

:bug: (Annotated region) (#352)

* :bug: (Annotated region)

Move annatated region in _CupertinoBottomSheetContainer and made overlayStyle depend on transitionBackgroundColor luminance

* :bug: (OverlayStyle)

remove computed overlayStyle in showCupertinoModalBottomSheet function
... ... @@ -18,6 +18,7 @@ import 'package:flutter/material.dart'
Colors,
MaterialLocalizations,
Theme,
ThemeData,
debugCheckHasMaterialLocalizations;
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
... ... @@ -30,6 +31,13 @@ const Radius _kDefaultTopRadius = Radius.circular(12);
const BoxShadow _kDefaultBoxShadow =
BoxShadow(blurRadius: 10, color: Colors.black12, spreadRadius: 5);
SystemUiOverlayStyle overlayStyleFromColor(Color color) {
final brightness = ThemeData.estimateBrightnessForColor(color);
return brightness == Brightness.dark
? SystemUiOverlayStyle.light
: SystemUiOverlayStyle.dark;
}
/// Cupertino Bottom Sheet Container
///
/// Clip the child widget to rectangle with top rounded corners and adds
... ... @@ -40,17 +48,20 @@ class _CupertinoBottomSheetContainer extends StatelessWidget {
final Color? backgroundColor;
final Radius topRadius;
final BoxShadow? shadow;
final SystemUiOverlayStyle? overlayStyle;
const _CupertinoBottomSheetContainer({
Key? key,
required this.child,
this.backgroundColor,
required this.topRadius,
this.overlayStyle,
this.shadow,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final scopedOverlayStyle = overlayStyle;
final topSafeAreaPadding = MediaQuery.of(context).padding.top;
final topPadding = _kPreviousPageVisibleOffset + topSafeAreaPadding;
... ... @@ -58,7 +69,7 @@ class _CupertinoBottomSheetContainer extends StatelessWidget {
BoxShadow(blurRadius: 10, color: Colors.black12, spreadRadius: 5);
final backgroundColor = this.backgroundColor ??
CupertinoTheme.of(context).scaffoldBackgroundColor;
return Padding(
Widget bottomSheetContainer = Padding(
padding: EdgeInsets.only(top: topPadding),
child: ClipRRect(
borderRadius: BorderRadius.vertical(top: topRadius),
... ... @@ -77,6 +88,13 @@ class _CupertinoBottomSheetContainer extends StatelessWidget {
),
),
);
if (scopedOverlayStyle != null) {
bottomSheetContainer = AnnotatedRegion<SystemUiOverlayStyle>(
value: scopedOverlayStyle,
child: bottomSheetContainer,
);
}
return bottomSheetContainer;
}
}
... ... @@ -111,7 +129,6 @@ Future<T?> showCupertinoModalBottomSheet<T>({
final barrierLabel = hasMaterialLocalizations
? MaterialLocalizations.of(context).modalBarrierDismissLabel
: '';
final result =
await Navigator.of(context, rootNavigator: useRootNavigator).push(
CupertinoModalBottomSheetRoute<T>(
... ... @@ -121,6 +138,7 @@ Future<T?> showCupertinoModalBottomSheet<T>({
backgroundColor: backgroundColor,
topRadius: topRadius,
shadow: shadow,
overlayStyle: overlayStyle,
),
secondAnimationController: secondAnimation,
expanded: expand,
... ... @@ -154,6 +172,9 @@ class CupertinoModalBottomSheetRoute<T> extends ModalSheetRoute<T> {
// Background color behind all routes
// Black by default
final Color? transitionBackgroundColor;
@Deprecated(
'Will be ignored. OverlayStyle is computed from luminance of transitionBackgroundColor',
)
final SystemUiOverlayStyle? overlayStyle;
CupertinoModalBottomSheetRoute({
... ... @@ -230,7 +251,6 @@ class CupertinoModalBottomSheetRoute<T> extends ModalSheetRoute<T> {
animationCurve: previousRouteAnimationCurve,
topRadius: topRadius,
backgroundColor: transitionBackgroundColor ?? Colors.black,
overlayStyle: overlayStyle,
);
}
}
... ... @@ -240,7 +260,6 @@ class _CupertinoModalTransition extends StatelessWidget {
final Radius topRadius;
final Curve? animationCurve;
final Color backgroundColor;
final SystemUiOverlayStyle? overlayStyle;
final Widget body;
... ... @@ -251,7 +270,6 @@ class _CupertinoModalTransition extends StatelessWidget {
required this.topRadius,
this.backgroundColor = Colors.black,
this.animationCurve,
this.overlayStyle,
}) : super(key: key);
@override
... ... @@ -268,50 +286,47 @@ class _CupertinoModalTransition extends StatelessWidget {
curve: animationCurve ?? Curves.easeOut,
);
return AnnotatedRegion<SystemUiOverlayStyle>(
value: overlayStyle ?? SystemUiOverlayStyle.light,
child: AnimatedBuilder(
animation: curvedAnimation,
child: body,
builder: (context, child) {
final progress = curvedAnimation.value;
final yOffset = progress * paddingTop;
final scale = 1 - progress / 10;
final radius = progress == 0
? 0.0
: (1 - progress) * startRoundCorner + progress * topRadius.x;
return Stack(
children: <Widget>[
Container(color: backgroundColor),
Transform.translate(
offset: Offset(0, yOffset),
child: Transform.scale(
scale: scale,
alignment: Alignment.topCenter,
child: ClipRRect(
borderRadius: BorderRadius.circular(radius),
child: CupertinoUserInterfaceLevel(
data: CupertinoUserInterfaceLevelData.elevated,
child: Builder(
builder: (context) => CupertinoTheme(
data: createPreviousRouteTheme(
context,
curvedAnimation,
),
child: CupertinoUserInterfaceLevel(
data: CupertinoUserInterfaceLevelData.base,
child: child!,
),
return AnimatedBuilder(
animation: curvedAnimation,
child: body,
builder: (context, child) {
final progress = curvedAnimation.value;
final yOffset = progress * paddingTop;
final scale = 1 - progress / 10;
final radius = progress == 0
? 0.0
: (1 - progress) * startRoundCorner + progress * topRadius.x;
return Stack(
children: <Widget>[
Container(color: backgroundColor),
Transform.translate(
offset: Offset(0, yOffset),
child: Transform.scale(
scale: scale,
alignment: Alignment.topCenter,
child: ClipRRect(
borderRadius: BorderRadius.circular(radius),
child: CupertinoUserInterfaceLevel(
data: CupertinoUserInterfaceLevelData.elevated,
child: Builder(
builder: (context) => CupertinoTheme(
data: createPreviousRouteTheme(
context,
curvedAnimation,
),
child: CupertinoUserInterfaceLevel(
data: CupertinoUserInterfaceLevelData.base,
child: child!,
),
),
),
),
),
),
],
);
},
),
),
],
);
},
);
}
... ... @@ -390,11 +405,13 @@ class CupertinoScaffoldInheirted extends InheritedWidget {
final AnimationController? animation;
final Radius? topRadius;
final Color transitionBackgroundColor;
const CupertinoScaffoldInheirted({
this.animation,
required super.child,
this.topRadius,
required this.transitionBackgroundColor,
}) : super();
@override
... ... @@ -440,6 +457,9 @@ class CupertinoScaffold extends StatefulWidget {
Duration? duration,
RouteSettings? settings,
BoxShadow? shadow,
@Deprecated(
'Will be ignored. OverlayStyle is computed from luminance of transitionBackgroundColor',
)
SystemUiOverlayStyle? overlayStyle,
}) async {
assert(debugCheckHasMediaQuery(context));
... ... @@ -451,6 +471,9 @@ class CupertinoScaffold extends StatefulWidget {
barrierLabel = MaterialLocalizations.of(context).modalBarrierDismissLabel;
}
final topRadius = CupertinoScaffold.of(context)!.topRadius;
final transitionBackgroundColor =
CupertinoScaffold.of(context)!.transitionBackgroundColor;
final overlayStyle = overlayStyleFromColor(transitionBackgroundColor);
final result = await Navigator.of(context, rootNavigator: useRootNavigator)
.push(CupertinoModalBottomSheetRoute<T>(
closeProgressThreshold: closeProgressThreshold,
... ... @@ -461,6 +484,7 @@ class CupertinoScaffold extends StatefulWidget {
backgroundColor: backgroundColor,
topRadius: topRadius ?? _kDefaultTopRadius,
shadow: shadow,
overlayStyle: overlayStyle,
),
expanded: expand,
barrierLabel: barrierLabel,
... ... @@ -473,7 +497,6 @@ class CupertinoScaffold extends StatefulWidget {
previousRouteAnimationCurve: previousRouteAnimationCurve,
duration: duration,
settings: settings,
overlayStyle: overlayStyle,
));
return result;
}
... ... @@ -495,12 +518,12 @@ class _CupertinoScaffoldState extends State<CupertinoScaffold>
return CupertinoScaffoldInheirted(
animation: animationController,
topRadius: widget.topRadius,
transitionBackgroundColor: widget.transitionBackgroundColor,
child: _CupertinoModalTransition(
secondaryAnimation: animationController,
body: widget.body,
topRadius: widget.topRadius,
backgroundColor: widget.transitionBackgroundColor,
overlayStyle: widget.overlayStyle,
),
);
}
... ...