Although the FittedBox scales the ListView properly, I cannot scroll the ListView horizontally:
import 'dart:ui';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
scrollBehavior: MyCustomScrollBehavior(),
home: Scaffold(
body: Container(
height: 200,
child: FittedBox(
alignment: Alignment(-1, -1),
fit: BoxFit.fitHeight,
child: Container(
height: 100,
child: ListView.builder(
itemCount: 20,
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemBuilder: (context, index) => Container(
width: 100,
height: 100,
child: Text(index.toString()),
decoration: BoxDecoration(border: Border.all(width: 3, color: Colors.red)))),
),
),
)),
);
}
}
class MyCustomScrollBehavior extends MaterialScrollBehavior {
// Override behavior methods and getters like dragDevices
@override
Set<PointerDeviceKind> get dragDevices => {
PointerDeviceKind.touch,
PointerDeviceKind.mouse,
};
}
Instead, the first few visible containers are displayed. The ListView scrolls properly without the FittedBox.
What's interesting is that if I specify a ScrollController() with an initialScrollOffset, the ListView is initially displayed at the specified scroll offset, but then animates back to offset 0.