Closed KristijanZic closed 2 weeks ago
I've dug some more into this and it seems that the flicker of the AppBar shape happens on AppBar elevation change when the content get's scrolled underneath the AppBar.
A workaround would be to set scrolledUnderElevation: 0.0,
in the AppBar as that doesn't seem to call any state change and thus the shape doesn't flicker. Unfortunately that means that we won't be able to use the elevation feature as per Material 3 HIG.
Thanks for the report. I'm able to reproduce the issue as well.
CC @Piinks
Up on investigating this issue, this looks this is reproduced due to custom shape having incomplete implementation, without lerp functions or a const constructor.
This can be reproduced with just Material
widget when updating elevation it rebuilds.
The custom shape without lerp functions fails to be identified by ShapeBorder.lerp
as identical
when the widget is rebuilt and falls back to parent shape which is ContinuousRectangleBorder
in this case.
Complete custom shappe implementation should have lerp functions to identify the custom shape and lerp it's properties.
To fix this please implement lerp functions.
class CustomAppBarShape extends ContinuousRectangleBorder {
const CustomAppBarShape({super.borderRadius = BorderRadius.zero});
@override
Path getOuterPath(Rect rect, {TextDirection? textDirection}) {
double height = rect.height + 80;
double width = rect.width;
print('SHAPE CALLED');
var path = Path();
path.lineTo(0, 0);
path.lineTo(width, 0);
path.lineTo(width, height + 40);
path.lineTo(0, height - 100);
path.close();
return path;
}
@override
ShapeBorder? lerpFrom(ShapeBorder? a, double t) {
if (a is CustomAppBarShape) {
return CustomAppBarShape(borderRadius: BorderRadiusGeometry.lerp(a.borderRadius, borderRadius, t)!);
}
return super.lerpFrom(a, t);
}
@override
ShapeBorder? lerpTo(ShapeBorder? b, double t) {
if (b is CustomAppBarShape) {
return CustomAppBarShape(borderRadius: BorderRadiusGeometry.lerp(b.borderRadius, borderRadius, t)!);
}
return super.lerpTo(b, t);
}
}
AppBar
This is similar to other shapes in the framework that do not reproduce this issue.
@HansMuller This seems to be working as expected.
Should we add an example for using custom shapes with Material
or Material
contained widgets such as AppBar
?
I would never say no to adding an example. In this case I think it would be particularly worthwhile!
I can confirm that this was in fact...a skill issue and it works perfectly fine with Taha's example. That said no linter has complained about the original example.
That said no linter has complained about the original example.
These are optional methods. The constructor alone would've fixed the issue, as it allows identical
method to properly compare custom shape objects. My new example include a comment for this and lerp functions, hopefully this will make it clear.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v
and a minimal reproduction of the issue.
Steps to reproduce
Following any setState (in app or via hot reloading) the AppBar shape will suddenly disappear when a SingleChildScrollView or a ListView in the same view moves from 0 or reaches 0. For the bug to happen again, setState has to be called again and the ScrollView/ListView has to move away from 0, if it was 0 initially, or reach 0 if it wasn't.
This bug only seems to be present in material 3, not material 2.
tested platforms: iOS, Android, Linux, macOS, web
affected platforms: iOS, Android, Linux, macOS, web affected channels: stable, master affected renderers: skia, impeller
Expected results
The AppBar shape should not ever disappear when set.
Actual results
AppBar shape clipper disappears when scrolling
Code sample
Code sample
```dart import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), home: const MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); final String title; @override StateScreenshots or Video
Screenshots / Video demonstration
https://github.com/flutter/flutter/assets/10299892/192b3a4a-9b74-46a5-b641-445f7cd8a6d0Logs
Logs
```console [Paste your logs here] ```Flutter Doctor output
Doctor output
```console [✓] Flutter (Channel master, 3.21.0-17.0.pre.19, on macOS 14.3.1 23D60 darwin-arm64, locale en-GB) • Flutter version 3.21.0-17.0.pre.19 on channel master at /Users/kristijanzic/Library/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 11d632e5dd (40 minutes ago), 2024-03-28 19:21:34 -0400 • Engine revision b917b24836 • Dart version 3.4.0 (build 3.4.0-282.0.dev) • DevTools version 2.34.1 [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1) • Android SDK at /Users/kristijanzic/Library/Android/sdk • Platform android-34, build-tools 33.0.1 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15E204a • CocoaPods version 1.15.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2023.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874) [✓] IntelliJ IDEA Community Edition (version 2023.1) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart [✓] VS Code (version 1.87.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.84.0 [✓] Connected device (4 available) • iPhone 15 Pro (mobile) • 6C492229-B053-4C1A-ADE2-785A83F06908 • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-4 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 14.3.1 23D60 darwin-arm64 • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 14.3.1 23D60 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 122.0.6261.57 [✓] Network resources • All expected network resources are available. • No issues found! ```