颤振中的水平滚动文本

Horizontal scroll Text in flutter

我正在尝试在 flutter web 应用程序上显示一个长文本而不进行剪裁或省略。为此,我想让它水平滚动。我从 https://www.geeksforgeeks.org/flutter-scrollable-text/

中找到了这段代码
import 'package:flutter/material.dart';

void main() {
runApp(MaterialApp(
    home: Scaffold(
    //adding App Bar
    appBar: AppBar(
        backgroundColor: Color.fromRGBO(15, 157, 88, 1),
        title: Text(
        "GeeksForGeeks",
        style: TextStyle(
            color: Colors.white,
        ),
        ),
    ),
    body: MyApp(),
    ),
));
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
    return Center(
    child: Container(
        // adding margin
        
        margin: const EdgeInsets.all(15.0),
        // adding padding
        
        padding: const EdgeInsets.all(3.0),
        decoration: BoxDecoration(
            
        // adding borders around the widget
        border: Border.all(
            color: Colors.blueAccent,
            width: 5.0,
        ),
        ),
        // SingleChildScrollView should be
        // wrapped in an Expanded Widget
        child: Expanded(
            
        //contains a single child which is scrollable
        child: SingleChildScrollView(
            
            //for horizontal scrolling
            scrollDirection: Axis.horizontal,
            child: Text(
            "GeeksForGeeks is a good platform to learn programming."
            " It is an educational website.",
            style: TextStyle(
                color: Colors.green,
                fontWeight: FontWeight.bold,
                fontSize: 20.0,
                letterSpacing: 3,
                wordSpacing: 3,
            ),
            ),
        ),
        ),
    ),
    );
}
}

但它不适用于 me.The 文本被剪裁但不可滚动。我尝试将 overflow: TextOverflow.visible 添加到文本小部件,但没有 result.I 没有任何其他想法,因为将 Text 包装在 SingleChildScrollView 中是我能想到的最简单的事情对于这个问题。

首先,要让 Flutter 检测滚动条下的项目,您现在必须使用 ListView。添加一个列表视图小部件,并在其下保留您的文本或其他小部件,基本上 flutter 将完美地检测到您的滚动小部件。

ListView 小部件中有一个名为 scrollDirection: 的 属性,您可以将值设置为 Axis.horizontal,就可以了。

如需进一步参考,请查看:How to create a horizontal list in flutter

提示:避免在旅途中学习 flutter 的 geeksforgeeks,学习起来很困难

问题的发生是因为 Expanded 小部件。删除它,它将正常工作,


class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Container(
        // adding margin

        margin: const EdgeInsets.all(15.0),
        // adding padding

        padding: const EdgeInsets.all(3.0),
        decoration: BoxDecoration(
          // adding borders around the widget
          border: Border.all(
            color: Colors.blueAccent,
            width: 5.0,
          ),
        ),

        child: SingleChildScrollView(
          //for horizontal scrolling
          scrollDirection: Axis.horizontal,
          child: Text(
            "GeeksForGeeks is a good platform to learn programming."
            " It is an educational website.",
            style: TextStyle(
              color: Colors.green,
              fontWeight: FontWeight.bold,
              fontSize: 20.0,
              letterSpacing: 3,
              wordSpacing: 3,
            ),
          ),
        ),
      ),
    );
  }
}