Closed WanderingTurtle closed 2 weeks ago
It works fine on my macbook pro. (Note i am on older flutter)
What I noticed was you are creating the scrollcontroller in your StatelessWidget. no good. Try using a StatefulWidget instead. If your controller keeps getting recreated, it could be the cause, the scroll position would keep resetting to 0?
Hi @WanderingTurtle, it appears that this has been fixed on the beta
& master
channels. See the recordings below.
Per our triage policy, I'll be closing this since it has been fixed on master/beta.
Thank you
3.19.6 | beta & master |
---|---|
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
mac: MacBook Air M1 2020 macOS: Sonoma 14.3.1
Here is a simple one vicinity TwoDimensionalScrollView implementation, and the vicinity is a very long Text widget.
In vscode I ran debug mode with macOS, and then with Chrome.
Expected results
On both macOS build and Chrome build, it should be scrollable horizontally with touch pad (two fingers wiping left or right).
Actual results
On macOS debug build, horizontal scrolling using touch pad has no effect. On Chrome debug build, horizontal scrolling using touch pad works ok.
Code sample
Code sample
``` import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.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, ), scrollBehavior: const MaterialScrollBehavior().copyWith( // Mouse dragging enabled for this demo dragDevices: PointerDeviceKind.values.toSet(), ), debugShowCheckedModeBanner: false, home: MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatelessWidget { final String title; MyHomePage({ Key? key, required this.title, }) : super(key: key); final ScrollController c1 = ScrollController(); final ScrollController c2 = ScrollController(); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text(title)), body: Scrollbar( trackVisibility: true, thumbVisibility: true, interactive: true, controller: c1, child: Scrollbar( trackVisibility: true, thumbVisibility: true, interactive: true, controller: c2, child: TwoDimensionalGridView( verticalDetails: ScrollableDetails.vertical( physics: const ClampingScrollPhysics(), controller: c1 ), horizontalDetails: ScrollableDetails.horizontal( physics: const ClampingScrollPhysics(), controller: c2 ), diagonalDragBehavior: DiagonalDragBehavior.free, delegate: TwoDimensionalChildBuilderDelegate( maxXIndex: 0, maxYIndex: 0, builder: (BuildContext context, ChildVicinity vicinity) { return Container( child: Text("asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasafsdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf") ); }), ), ) ) ); } } class TwoDimensionalGridView extends TwoDimensionalScrollView { const TwoDimensionalGridView({ super.key, super.primary, super.mainAxis = Axis.vertical, super.verticalDetails = const ScrollableDetails.vertical(), super.horizontalDetails = const ScrollableDetails.horizontal(), required TwoDimensionalChildBuilderDelegate delegate, super.cacheExtent, super.diagonalDragBehavior = DiagonalDragBehavior.none, super.dragStartBehavior = DragStartBehavior.start, super.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual, super.clipBehavior = Clip.hardEdge, }) : super(delegate: delegate); @override Widget buildViewport( BuildContext context, ViewportOffset verticalOffset, ViewportOffset horizontalOffset, ) { return TwoDimensionalGridViewport( horizontalOffset: horizontalOffset, horizontalAxisDirection: horizontalDetails.direction, verticalOffset: verticalOffset, verticalAxisDirection: verticalDetails.direction, mainAxis: mainAxis, delegate: delegate as TwoDimensionalChildBuilderDelegate, cacheExtent: cacheExtent, clipBehavior: clipBehavior, ); } } class TwoDimensionalGridViewport extends TwoDimensionalViewport { const TwoDimensionalGridViewport({ super.key, required super.verticalOffset, required super.verticalAxisDirection, required super.horizontalOffset, required super.horizontalAxisDirection, required TwoDimensionalChildBuilderDelegate super.delegate, required super.mainAxis, super.cacheExtent, super.clipBehavior = Clip.hardEdge, }); @override RenderTwoDimensionalViewport createRenderObject(BuildContext context) { return RenderTwoDimensionalGridViewport( horizontalOffset: horizontalOffset, horizontalAxisDirection: horizontalAxisDirection, verticalOffset: verticalOffset, verticalAxisDirection: verticalAxisDirection, mainAxis: mainAxis, delegate: delegate as TwoDimensionalChildBuilderDelegate, childManager: context as TwoDimensionalChildManager, cacheExtent: cacheExtent, clipBehavior: clipBehavior, ); } @override void updateRenderObject( BuildContext context, RenderTwoDimensionalGridViewport renderObject, ) { renderObject ..horizontalOffset = horizontalOffset ..horizontalAxisDirection = horizontalAxisDirection ..verticalOffset = verticalOffset ..verticalAxisDirection = verticalAxisDirection ..mainAxis = mainAxis ..delegate = delegate ..cacheExtent = cacheExtent ..clipBehavior = clipBehavior; } } class RenderTwoDimensionalGridViewport extends RenderTwoDimensionalViewport { RenderTwoDimensionalGridViewport({ required super.horizontalOffset, required super.horizontalAxisDirection, required super.verticalOffset, required super.verticalAxisDirection, required TwoDimensionalChildBuilderDelegate delegate, required super.mainAxis, required super.childManager, super.cacheExtent, super.clipBehavior = Clip.hardEdge, }) : super(delegate: delegate); @override void layoutChildSequence() { final ChildVicinity vicinity = ChildVicinity(xIndex: 0, yIndex: 0); final RenderBox child = buildOrObtainChildFor(vicinity)!; double intrinsicHeight = child.getMaxIntrinsicHeight(double.maxFinite); double height = intrinsicHeight; double width = child.getMaxIntrinsicWidth(double.maxFinite) + 100; child.layout(BoxConstraints(minHeight: height, maxHeight: height, minWidth: width, maxWidth: width)); parentDataOf(child).layoutOffset = Offset(-horizontalOffset.pixels, -verticalOffset.pixels); verticalOffset.applyContentDimensions( 0.0, clampDouble(height - viewportDimension.height, 0.0, double.infinity), ); horizontalOffset.applyContentDimensions( 0.0, clampDouble(width - viewportDimension.width, 0.0, double.infinity), ); } } ```Screenshots or Video
No response
Logs
No response
Flutter Doctor output
Doctor output
``` Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.19.3, on macOS 14.3.1 23D60 darwin-arm64, locale en-CN) [✗] Android toolchain - develop for Android devices ✗ Unable to locate Android SDK. Install Android Studio from: https://developer.android.com/studio/index.html On first launch it will assist you in installing the Android SDK components. (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions). If the Android SDK has been installed to a custom location, please use `flutter config --android-sdk` to update to that location. [✓] Xcode - develop for iOS and macOS (Xcode 15.3) [✓] Chrome - develop for the web [!] Android Studio (not installed) [✓] VS Code (version 1.84.2) [✓] Connected device (2 available) [✓] Network resources ! Doctor found issues in 2 categories. ```