Comments (8)
I would never say no to adding an example. In this case I think it would be particularly worthwhile!
from flutter.
Thanks for the report. I'm able to reproduce the issue as well.
flutter doctor -v (stable and master)
[✓] Flutter (Channel stable, 3.19.5, on macOS 14.1 23B74 darwin-x64, locale en-VN)
• Flutter version 3.19.5 on channel stable at /Users/huynq/Documents/GitHub/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 300451adae (25 hours ago), 2024-03-27 21:54:07 -0500
• Engine revision e76c956498
• Dart version 3.3.3
• DevTools version 2.31.1
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/huynq/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• ANDROID_HOME = /Users/huynq/Library/Android/sdk
• 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.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15C500b
• 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
• android-studio-dir = /Applications/Android Studio.app/
• Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
[✓] VS Code (version 1.87.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.84.0
[✓] Connected device (3 available)
• Pixel 7 (mobile) • 2B171FDH20084L • android-arm64 • Android 14 (API 34)
• macOS (desktop) • macos • darwin-x64 • macOS 14.1 23B74 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 123.0.6312.86
[✓] Network resources
• All expected network resources are available.
• No issues found!
[!] Flutter (Channel master, 3.21.0-17.0.pre.24, on macOS 14.1 23B74 darwin-x64, locale en-VN)
• Flutter version 3.21.0-17.0.pre.24 on channel master at /Users/huynq/Documents/GitHub/flutter_master
! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 1a2f34ab5b (63 minutes ago), 2024-03-28 19:39:17 -0700
• Engine revision 68aa9ba386
• Dart version 3.4.0 (build 3.4.0-282.0.dev)
• DevTools version 2.34.1
• If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/huynq/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• ANDROID_HOME = /Users/huynq/Library/Android/sdk
• 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.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15C500b
• 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
• android-studio-dir = /Applications/Android Studio.app/
• Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
[✓] VS Code (version 1.87.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.84.0
[✓] Connected device (3 available)
• Pixel 7 (mobile) • 2B171FDH20084L • android-arm64 • Android 14 (API 34)
• macOS (desktop) • macos • darwin-x64 • macOS 14.1 23B74 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 123.0.6312.86
[✓] Network resources
• All expected network resources are available.
! Doctor found issues in 1 category.
from flutter.
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.
expand to view the code sample
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
int _elevation = 0;
void _incrementElevation() {
setState(() {
_elevation++;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(useMaterial3: false),
home: Scaffold(
body: Center(
child: GestureDetector(
onTap: () {
_incrementElevation();
},
child: Material(
elevation: _elevation.toDouble(),
color: Colors.red,
shape: CustomShape(),
child: const SizedBox(
width: 100,
height: 100,
child: Center(child: Text('Tap me')),
),
),
),
),
),
);
}
}
class CustomShape extends ContinuousRectangleBorder {
// const CustomShape();
@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 CustomShape) {
// return CustomShape();
// }
// return super.lerpFrom(a, t);
// }
// @override
// ShapeBorder? lerpTo(ShapeBorder? b, double t) {
// if (b is CustomShape) {
// return CustomShape();
// }
// return super.lerpTo(b, t);
// }
}
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);
}
}
Fixed code sample for AppBar
expand to view the code sample
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
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
shape: const CustomAppBarShape(),
),
body: SingleChildScrollView(
primary: true,
child: Column(
children: [
for (var i = 0; i < 100; i++)
ListTile(
title: Text('Test $i'),
leading: Text('$_counter'),
),
],
),
),
// The bug happens both with SingleChildScrollView and ListView scrolling
// body: ListView(
// primary: true,
// children: [
// for (var i = 0; i < 1000; i++)
// ListTile(
// title: Text('Test $i'),
// leading: Text('$_counter'),
// ),
// ],
// ),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
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);
}
}
Preview
This is similar to other shapes in the framework that do not reproduce this issue.
flutter/packages/flutter/lib/src/painting/stadium_border.dart
Lines 26 to 37 in 45deb49
from flutter.
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.
from flutter.
CC @Piinks
from flutter.
@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
?
from flutter.
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.
from flutter.
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.
from flutter.
Related Issues (20)
- Composing characters (e.g. Umlauts) using physical keyboard on iOS generates two characters HOT 1
- camera add automaticallyEnablesLowLightBoost HOT 5
- Why [TabBar] has an offset of 52.0 pixels when [TabBar.isScrollable] is true by default HOT 2
- Disable Samsung keyboard toolbar in flutter 3.19.5 HOT 2
- [image_picker] iOS native picker is misplaced when running a flutter web project HOT 2
- Http download is 3x times slower on Web vs Desktop HOT 2
- Fluttertts not working in ios HOT 2
- Implementing native view on iOS make app crash with using the Impeller rendering backend HOT 20
- two_dimensional_scrollables package enhancement: TableView / ListView widget with column sorting/resizing and row selection
- TLHC platform views on Android 14/15 stop updating on resume HOT 18
- Chips delete icon ignores `IconTheme` from `Chip.iconTheme` and `ChipThemeData.iconTheme` HOT 2
- Flutter Project Hitting libc++_shared.so not found on Windows 11 Home HOT 2
- Allow overriding `Widget.canUpdate` behavior HOT 5
- Enforce `parallelizable=NO` in iOS/macOS package native unit tests
- Engine -> Framework roll failing on super_editor customer tests HOT 13
- Filled text field active indicator overflows container bounds HOT 1
- mac-24 & mac-41 lost external connection phone device. HOT 2
- Weird blurring effect if the page has background with a blur in a PageView. HOT 3
- Run engine unit tests against debug builds of skwasm/canvaskit
- [go_router] Replacing a ModalBottomSheetRoute with Another ModalBottomSheetRoute Fails HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter.