I'm having a hard time making a flutter screen be scrollable both horizontally and vertically. I can make it work in one direction but fail when I try it in both directions.
Here is a mock app. For background, I'm targeting the web, where the information should be accessible by keyboard & mouse even if it's outside the immediate viewing area.
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
scrollDirection: Axis.horizontal,
children: [
ListView(
scrollDirection: Axis.vertical,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
children: [
for (var i = 0; i < 4; i++)
Container(
child: Text('Header $i'),
width: 300,
height: 100,
color: Colors.greenAccent,
margin: const EdgeInsets.all(20)),
],
),
...[
for (var i = 0; i < 50; i++)
Container(
child: Text('Column $i'),
width: 150,
height: 50,
color: Colors.orange,
margin: const EdgeInsets.all(10),
)
],
],
)
],
)
],
),
);
}
}
Thank you for any suggestions on how to make this work!
Tony