Skip to content

Instantly share code, notes, and snippets.

@muirandy
Created October 24, 2018 21:24
Show Gist options
  • Save muirandy/690e349b14d21ce5cf02f2507da85cf9 to your computer and use it in GitHub Desktop.
Save muirandy/690e349b14d21ce5cf02f2507da85cf9 to your computer and use it in GitHub Desktop.
Flutter: Scrolling in 2 dimensions. Doesn't do diagonals, nor pinch/zoom or ScrollBars.
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
home: new MyHomePage(),
));
}
class MyHomePage extends StatelessWidget {
Widget build(BuildContext context) {
ThemeData themeData = Theme.of(context);
return new Scaffold(
body: new SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: new SizedBox(
width: 4000.0,
child: new ListView.builder(
itemBuilder: (BuildContext context, int i) {
return new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: _createText(20),
);
},
),
),
),
);
}
List<Widget> _createText(int i) {
List<Widget> widgets = [];
for (int r = 1; r <= 20; r++) {
widgets.add(newCell("Row " + r.toString() + " Column " + i.toString()));
}
return widgets;
}
Widget newCell(String data) {
return CircleAvatar(
maxRadius: 80.0,
child: Padding(
padding: EdgeInsets.all(15.0),
child: Text(data),
));
}
}
@bobagold
Copy link

Hi Andy. Thank you for the snippet. I put it to dartpad https://dartpad.dev/690e349b14d21ce5cf02f2507da85cf9 and found out a typo: there should be _createText(i), not _createText(20). Cheers, Vladimir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment