简体   繁体   中英

Adding both vertical and horizontal scrolling to ListView

How can I make the Row s inside a vertical ListView , scrollable horizontally.

This is what my app looks like:

在此处输入图片说明

I want the user to be able to scroll the ListView both horizontally (to see the contents of the Row ) and vertically to see new list items. This behavior is like how you would scroll a DataTable in Flutter:

在此处输入图片说明

Here is the build method (based on the Flutter project template):

@override
Widget build(BuildContext context) {
  final List<String> rows = [
    "This is a row with some very long text ... That goes on and on",
    "This class is the configuration for the state.",
    "case the title) provided by the parent (in this case the App widget) and",
    "always marked \"final\"."
  ];

  return Scaffold(
    appBar: AppBar(title: Text("ListView")),
    body: ListView(
      padding: EdgeInsets.all(10),
      children: <Widget>[
        for (final String row in rows)
          Row(
            children: <Widget>[Text(row)],
          )
      ],
    ),
  );
}

Update: Wrapping the Text in Expanded doesn't work as it causes the text to wrap onto multiple lines. I want the text to remain on a single line.

Finally After a deep search found this finally

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new SingleChildScrollView(
        scrollDirection: Axis.horizontal,
        child: new SizedBox(
          width: 1000.0,
          child: new ListView.builder(
            itemBuilder: (BuildContext context, int i) {
              return new Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: new List.generate(5, (int j) {
                  return new Text("$i,$j");
                }),
              );
            },
          ),
        ),
      ),
    );
  }

Original source Vote up his answer too

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM