Created
October 24, 2018 21:24
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.