Skip to content

Commit

Permalink
Fix Flutter 3.22 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
FauconSpartiate committed May 21, 2024
1 parent 16c124c commit e927b60
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 47 deletions.
6 changes: 6 additions & 0 deletions lib/localization/material_localization/lb_intl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ class LbMaterialLocalizations extends GlobalMaterialLocalizations {
@override
String get backButtonTooltip => 'Zerèck';

@override
String get clearButtonTooltip => 'Text läschen';

@override
String get bottomSheetLabel => 'Usiicht am ënneren Rand';

Expand Down Expand Up @@ -612,6 +615,9 @@ class LbMaterialLocalizations extends GlobalMaterialLocalizations {
@override
String get selectYearSemanticsLabel => 'Joer auswielen';

@override
String get selectedDateLabel => 'Gewielt';

@override
String? get selectedRowCountTitleFew => null;

Expand Down
8 changes: 4 additions & 4 deletions lib/ui/utilities/app_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class AppTheme {
space: 1,
indent: 16,
endIndent: 16,
color: colorScheme.surfaceVariant,
color: colorScheme.surfaceContainerHighest,
),
pageTransitionsTheme: const PageTransitionsTheme(
builders: {
Expand Down Expand Up @@ -165,9 +165,9 @@ class AppTheme {
titleTextStyle: theme.appBarTheme.titleTextStyle,
),
switchTheme: theme.switchTheme.copyWith(
thumbIcon: MaterialStateProperty.resolveWith<Icon?>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.selected)) {
thumbIcon: WidgetStateProperty.resolveWith<Icon?>(
(Set<WidgetState> states) {
if (states.contains(WidgetState.selected)) {
return const Icon(Icons.check);
}
return null;
Expand Down
106 changes: 66 additions & 40 deletions lib/ui/widgets/better_app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,8 @@ class BetterAppBar extends StatefulWidget implements PreferredSizeWidget {
/// overall theme's brightness is [Brightness.light], and [ColorScheme.surface]
/// if the overall theme's brightness is [Brightness.dark].
///
/// If this color is a [MaterialStateColor] it will be resolved against
/// [MaterialState.scrolledUnder] when the content of the app's
/// If this color is a [WidgetStateColor] it will be resolved against
/// [WidgetState.scrolledUnder] when the content of the app's
/// primary scrollable overlaps the app bar.
/// {@endtemplate}
///
Expand Down Expand Up @@ -774,10 +774,10 @@ class _BetterAppBarState extends State<BetterAppBar> {
}
}

Color _resolveColor(Set<MaterialState> states, Color? widgetColor, Color? themeColor, Color defaultColor) {
return MaterialStateProperty.resolveAs<Color?>(widgetColor, states) ??
MaterialStateProperty.resolveAs<Color?>(themeColor, states) ??
MaterialStateProperty.resolveAs<Color>(defaultColor, states);
Color _resolveColor(Set<WidgetState> states, Color? widgetColor, Color? themeColor, Color defaultColor) {
return WidgetStateProperty.resolveAs<Color?>(widgetColor, states) ??
WidgetStateProperty.resolveAs<Color?>(themeColor, states) ??
WidgetStateProperty.resolveAs<Color>(defaultColor, states);
}

SystemUiOverlayStyle _systemOverlayStyleForBrightness(Brightness brightness, [Color? backgroundColor]) {
Expand All @@ -803,8 +803,8 @@ class _BetterAppBarState extends State<BetterAppBar> {
final ModalRoute<dynamic>? parentRoute = ModalRoute.of(context);

final FlexibleSpaceBarSettings? settings = context.dependOnInheritedWidgetOfExactType<FlexibleSpaceBarSettings>();
final Set<MaterialState> states = <MaterialState>{
if (settings?.isScrolledUnder ?? _scrolledUnder) MaterialState.scrolledUnder,
final Set<WidgetState> states = <WidgetState>{
if (settings?.isScrolledUnder ?? _scrolledUnder) WidgetState.scrolledUnder,
};

final bool hasDrawer = scaffold?.hasDrawer ?? false;
Expand All @@ -820,11 +820,20 @@ class _BetterAppBarState extends State<BetterAppBar> {
defaults.backgroundColor!,
);

final Color scrolledUnderBackground = _resolveColor(
states,
widget.backgroundColor,
appBarTheme.backgroundColor,
Theme.of(context).colorScheme.surfaceContainer,
);

final Color effectiveBackgroundColor = states.contains(WidgetState.scrolledUnder) ? scrolledUnderBackground : backgroundColor;

final Color foregroundColor = widget.foregroundColor ?? appBarTheme.foregroundColor ?? defaults.foregroundColor!;

final double elevation = widget.elevation ?? appBarTheme.elevation ?? defaults.elevation!;

final double effectiveElevation = states.contains(MaterialState.scrolledUnder)
final double effectiveElevation = states.contains(WidgetState.scrolledUnder)
? widget.scrolledUnderElevation ?? appBarTheme.scrolledUnderElevation ?? defaults.scrolledUnderElevation ?? elevation
: elevation;

Expand Down Expand Up @@ -1074,7 +1083,7 @@ class _BetterAppBarState extends State<BetterAppBar> {
appBarTheme.systemOverlayStyle ??
defaults.systemOverlayStyle ??
_systemOverlayStyleForBrightness(
ThemeData.estimateBrightnessForColor(backgroundColor),
ThemeData.estimateBrightnessForColor(effectiveBackgroundColor),
// Make the status bar transparent for M3 so the elevation overlay
// color is picked up by the statusbar.
theme.useMaterial3 ? const Color(0x00000000) : null,
Expand All @@ -1085,11 +1094,17 @@ class _BetterAppBarState extends State<BetterAppBar> {
child: AnnotatedRegion<SystemUiOverlayStyle>(
value: overlayStyle,
child: Material(
color: backgroundColor,
color: theme.useMaterial3 ? effectiveBackgroundColor : backgroundColor,
elevation: effectiveElevation,
type: widget.forceMaterialTransparency ? MaterialType.transparency : MaterialType.canvas,
shadowColor: widget.shadowColor ?? appBarTheme.shadowColor ?? defaults.shadowColor,
surfaceTintColor: widget.surfaceTintColor ?? appBarTheme.surfaceTintColor ?? defaults.surfaceTintColor,
surfaceTintColor: widget.surfaceTintColor ??
appBarTheme.surfaceTintColor
// M3 `defaults.surfaceTint` is Colors.transparent now. It is not used
// here because otherwise, it will cause breaking change for
// `scrolledUnderElevation`.
??
(theme.useMaterial3 ? theme.colorScheme.surfaceTint : null),
shape: widget.shape ?? appBarTheme.shape ?? defaults.shape,
child: Semantics(
explicitChildNodes: true,
Expand Down Expand Up @@ -1140,6 +1155,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
required this.forceMaterialTransparency,
required this.clipBehavior,
required this.variant,
required this.accessibleNavigation,
}) : assert(primary || topPadding == 0.0),
_bottomHeight = bottom?.preferredSize.height ?? 0.0;

Expand Down Expand Up @@ -1177,6 +1193,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
final bool forceMaterialTransparency;
final Clip? clipBehavior;
final _SliverAppVariant variant;
final bool accessibleNavigation;

@override
double get minExtent => collapsedHeight;
Expand Down Expand Up @@ -1204,8 +1221,9 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {

final bool isScrolledUnder = overlapsContent || forceElevated || (pinned && shrinkOffset > maxExtent - minExtent);
final bool isPinnedWithOpacityFade = pinned && floating && bottom != null && extraToolbarHeight == 0.0;
final double toolbarOpacity =
!pinned || isPinnedWithOpacityFade ? clampDouble(visibleToolbarHeight / (toolbarHeight ?? kToolbarHeight), 0.0, 1.0) : 1.0;
final double toolbarOpacity = !accessibleNavigation && (!pinned || isPinnedWithOpacityFade)
? clampDouble(visibleToolbarHeight / (toolbarHeight ?? kToolbarHeight), 0.0, 1.0)
: 1.0;
final Widget? effectiveTitle = switch (variant) {
_SliverAppVariant.small => title,
_SliverAppVariant.medium || _SliverAppVariant.large => AnimatedOpacity(
Expand Down Expand Up @@ -1294,7 +1312,8 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
toolbarTextStyle != oldDelegate.toolbarTextStyle ||
titleTextStyle != oldDelegate.titleTextStyle ||
systemOverlayStyle != oldDelegate.systemOverlayStyle ||
forceMaterialTransparency != oldDelegate.forceMaterialTransparency;
forceMaterialTransparency != oldDelegate.forceMaterialTransparency ||
accessibleNavigation != oldDelegate.accessibleNavigation;
}

@override
Expand Down Expand Up @@ -1973,6 +1992,7 @@ class _BetterSliverAppBarState extends State<BetterSliverAppBar> with TickerProv
forceMaterialTransparency: widget.forceMaterialTransparency,
clipBehavior: widget.clipBehavior,
variant: widget._variant,
accessibleNavigation: MediaQuery.of(context).accessibleNavigation,
),
),
);
Expand Down Expand Up @@ -2183,42 +2203,48 @@ class _RenderExpandedTitleBox extends RenderShiftedBox {
return child == null ? 0.0 : child.getMinIntrinsicWidth(double.infinity) + padding.horizontal;
}

Size _computeSize(BoxConstraints constraints, ChildLayouter layoutChild) {
@override
Size computeDryLayout(BoxConstraints constraints) => child == null ? Size.zero : constraints.biggest;

Offset _childOffsetFromSize(Size childSize, Size size) {
assert(child != null);
assert(padding.isNonNegative);
assert(titleAlignment.y == 1.0);
// yAdjustment is the minimum additional y offset to shift the child in
// the visible vertical space when BetterAppBar is fully expanded. The goal is to
// prevent the expanded title from being clipped when the expanded title
// widget + the bottom padding is too tall to fit in the flexible space (the
// top padding is basically ignored since the expanded title is
// bottom-aligned).
final double yAdjustment = clampDouble(childSize.height + padding.bottom - maxExtent, 0, padding.bottom);
final double offsetX = (titleAlignment.x + 1) / 2 * (size.width - padding.horizontal - childSize.width) + padding.left;
final double offsetY = size.height - childSize.height - padding.bottom + yAdjustment;
return Offset(offsetX, offsetY);
}

@override
double? computeDryBaseline(covariant BoxConstraints constraints, TextBaseline baseline) {
final RenderBox? child = this.child;
if (child == null) {
return Size.zero;
return null;
}
layoutChild(child, constraints.widthConstraints().deflate(padding));
return constraints.biggest;
final BoxConstraints childConstraints = constraints.widthConstraints().deflate(padding);
final BaselineOffset result = BaselineOffset(child.getDryBaseline(childConstraints, baseline)) +
_childOffsetFromSize(child.getDryLayout(childConstraints), getDryLayout(constraints)).dy;
return result.offset;
}

@override
Size computeDryLayout(BoxConstraints constraints) => _computeSize(constraints, ChildLayoutHelper.dryLayoutChild);

@override
void performLayout() {
final RenderBox? child = this.child;
if (child == null) {
this.size = constraints.smallest;
size = constraints.smallest;
return;
}
final Size size = this.size = _computeSize(constraints, ChildLayoutHelper.layoutChild);
final Size childSize = child.size;

assert(padding.isNonNegative);
assert(titleAlignment.y == 1.0);
// yAdjustement is the minimum additional y offset to shift the child in
// the visible vertical space when AppBar is fully expanded. The goal is to
// prevent the expanded title from being clipped when the expanded title
// widget + the bottom padding is too tall to fit in the flexible space (the
// top padding is basically ignored since the expanded title is
// bottom-aligned).
final double yAdjustement = clampDouble(childSize.height + padding.bottom - maxExtent, 0, padding.bottom);
final double offsetY = size.height - childSize.height - padding.bottom + yAdjustement;
final double offsetX = (titleAlignment.x + 1) / 2 * (size.width - padding.horizontal - childSize.width) + padding.left;

size = constraints.biggest;
child.layout(constraints.widthConstraints().deflate(padding), parentUsesSize: true);
final BoxParentData childParentData = child.parentData! as BoxParentData;
childParentData.offset = Offset(offsetX, offsetY);
childParentData.offset = _childOffsetFromSize(child.size, size);
}
}

Expand Down Expand Up @@ -2289,7 +2315,7 @@ class _AppBarDefaultsM3 extends AppBarTheme {
Color? get shadowColor => Colors.transparent;

@override
Color? get surfaceTintColor => _colors.surfaceTint;
Color? get surfaceTintColor => Colors.transparent;

@override
IconThemeData? get iconTheme => IconThemeData(
Expand Down
6 changes: 3 additions & 3 deletions lib/ui/widgets/charts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ class _StandardLineChartState extends State<StandardLineChart> {
verticalInterval: widget.xGridInterval.toDouble(),
getDrawingHorizontalLine: (value) {
return FlLine(
color: Theme.of(context).colorScheme.onBackground.withOpacity(0.1),
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.1),
strokeWidth: 1,
);
},
getDrawingVerticalLine: (value) {
return FlLine(
color: Theme.of(context).colorScheme.onBackground.withOpacity(0.1),
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.1),
strokeWidth: 1,
);
},
Expand All @@ -133,7 +133,7 @@ class _StandardLineChartState extends State<StandardLineChart> {
),
borderData: FlBorderData(
show: true,
border: Border.all(color: Theme.of(context).colorScheme.surfaceVariant),
border: Border.all(color: Theme.of(context).colorScheme.surfaceContainerHighest),
),
minX: minX,
maxX: maxX,
Expand Down

0 comments on commit e927b60

Please sign in to comment.