how to create a row of scrollable text boxes or widgets in flutter inside a ListView?

前端 未结 6 1084
悲哀的现实
悲哀的现实 2021-01-01 11:46

1.Please, can someone tell me how to create a row of text boxes that are scrollable to left or right in flutter inside a ListView. I can see that I am trying to define an in

6条回答
  •  既然无缘
    2021-01-01 11:57

    I have managed to do this by using ListView.builder()

    Here is the full code:

    import 'package:flutter/material.dart';
    
    
    void main() {
      runApp(new MaterialApp(
          home: new MyApp()));
    }
    
    class MyApp extends StatefulWidget {
      @override
      State createState() {
        return new _MyAppState();
      }
    }
    
    class _MyAppState extends State {
    
      @override
      Widget build(BuildContext context) {
        return new Scaffold(
            appBar: new AppBar(
              title: new Text("Scroll on the Horizon"),
              centerTitle: true,
            ),
            body: new ListView.builder(
              scrollDirection: Axis.horizontal,
              itemBuilder: (BuildContext context, int index) {
                return new Row(
                  children: [
                    new Text("Let ", style: new TextStyle(color: Colors.blue),),
                    new Text("me ", style: new TextStyle(color: Colors.red)),
                    new Text("scroll ", style: new TextStyle(color: Colors.green)),
                    new Text("horizontally ",
                        style: new TextStyle(color: Colors.orange)),
                    new Text("Let ", style: new TextStyle(color: Colors.blue),),
                    new Text("me ", style: new TextStyle(color: Colors.red)),
                    new Text("scroll ", style: new TextStyle(color: Colors.green)),
                    new Text("horizontally ",
                        style: new TextStyle(color: Colors.orange)),
                    new Text("Let ", style: new TextStyle(color: Colors.blue),),
                    new Text("me ", style: new TextStyle(color: Colors.red)),
                    new Text("scroll ", style: new TextStyle(color: Colors.green)),
                    new Text("horizontally ",
                        style: new TextStyle(color: Colors.orange)),
                    new Text("Let ", style: new TextStyle(color: Colors.blue),),
                    new Text("me ", style: new TextStyle(color: Colors.red)),
                    new Text("scroll ", style: new TextStyle(color: Colors.green)),
                    new Text("horizontally ",
                        style: new TextStyle(color: Colors.orange)),
    
                  ],
    
                );
              },
    
    
            ));
      }
    
    }
    

    Do not forget to set scrollDirection property to Axis.horizontal, since it is defaulted to the vertical value.

提交回复
热议问题