-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Hello Flutter team
I recently upgraded flutter (i had fallen a number of versions behind and don't recall exact version) and had working code leveraging DraggableScrollableSheet and a controller that worked fine programmatically that was able to open and close the sheet (via a convenience button). I've recently updated to latest flutter and this code is no longer working, and i've also been able to strip out into minimal program from flutter sample program and can also see odd buggy behavior using the DraggableScrollableController The dragging works fine, but through the controller this seems to no longer work properly.
Just to clarify, this is the DraggableScrollableController to animate the sheet opening and closing, not the controller for scrolling within the sheet.
Thanks!
Code sample
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
List<String> animalNames = ['Elephant', 'Tiger', 'Kangaroo'];
List<String> animalFamily = ['Elephantidae', 'Panthera', 'Macropodidae'];
List<String> animalLifeSpan = ['60-70', '8-10', '15-20'];
List<String> animalWeight = ['2700-6000', '90-310', '47-66'];
int selectedTile = 0;
DraggableScrollableController panelSC = DraggableScrollableController();
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Stack(
children: [
OutlinedButton(
//elevation: 1.0,
onPressed: () {
setState(() {
print('expanding');
panelSC.animateTo(.8,
duration: Duration(milliseconds: 400),
curve: Curves.easeInOutBack);
});
},
style: OutlinedButton.styleFrom(
//primary: Colors.white,
padding: EdgeInsets.symmetric(vertical: 15, horizontal: 10),
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
),
// padding: EdgeInsets.symmetric(vertical: 15),
// shape: RoundedRectangleBorder(
// borderRadius: BorderRadius.circular(5.0),
// ),
// color: Colors.white,
child: Text(
'expand',
style: TextStyle(
color: Colors.black,
letterSpacing: 1,
fontSize: 14.0,
fontWeight: FontWeight.normal,
fontFamily: 'Roboto',
),
),
),
DraggableScrollableSheet(
controller: panelSC,
initialChildSize: .2,
minChildSize: .2,
maxChildSize: .6,
builder:
(BuildContext context, ScrollController scrollController) {
return Container(
color: Colors.lightGreen[100],
child: ListView(
controller: scrollController,
children: [
ListTile(
title: Text(
"NAME",
),
subtitle: Text(
animalNames[selectedTile],
),
),
ListTile(
title: Text(
"FAMILY",
),
subtitle: Text(
animalFamily[selectedTile],
),
),
ListTile(
title: Text(
"LIFESPAN",
),
subtitle: Text(
animalLifeSpan[selectedTile],
),
),
ListTile(
title: Text(
"WEIGHT",
),
subtitle: Text(
animalWeight[selectedTile],
),
),
],
),
);
},
),
],
) // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
Logs
Flutter (Channel stable, 3.3.6, on macOS 11.6 20G165 darwin-x64, locale en-US)
• Flutter version 3.3.6 on channel stable at /Users/nathanholm/devTools/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 6928314d50 (24 hours ago), 2022-10-25 16:34:41 -0400
• Engine revision 3ad69d7be3
• Dart version 2.18.2
• DevTools version 2.15.0
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/nathanholm/Library/Android/sdk
✗ cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 13C100
• CocoaPods version 1.11.3