【问题标题】:How to align a text widget in the bottom left corner of my flutter app?如何在我的颤振应用程序的左下角对齐文本小部件?
【发布时间】:2021-11-25 10:47:08
【问题描述】:

作为 Flutter 的初学者,我正在开发一个 Quotes 应用程序。所以我同时使用图像和文本来使这些 Quotes 在美学上更具吸引力。现在我想在我的应用程序的左下角添加一个简单的数字。它用于向用户显示他们现在所在的页面,无论我在做什么,都会向我显示错误。如果可能,请提供帮助。[这里 p1()、p2() 等是我创建的一些页面]

class OverviewScreen extends StatefulWidget {
const OverviewScreen({key, Key,}) : super(key: key);
@override
_OverviewScreenState createState() => _OverviewScreenState();
}

class _OverviewScreenState extends State<OverviewScreen> {
PageController pageController =PageController(initialPage: 0);

@override
Widget build(BuildContext context) {
return MaterialApp(
  home:Scaffold(
    drawer:NavigationDrawerWidget() ,
    extendBodyBehindAppBar: true,
    appBar: AppBar(
        title: Text("Hu   R   Rehman",
        style: TextStyle(fontFamily: "MonteCarlo"),),
        centerTitle: true,


      shape:RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(bottom: Radius.circular(16))
      ),
      backgroundColor: Colors.transparent,
      elevation: 0,

    ),
    body:Center(
      child: Stack(
        alignment: Alignment.center,
        children: [
          PageView(
            controller:pageController,
            children: [
              Stack(
                alignment: Alignment.center,
                children: [
                  Image(image: AssetImage('Image/soc1.jpg'),
                    fit: BoxFit.cover,
                    width: double.infinity,
                    height: double.infinity,),
                  const Text(' Hello world ',
                    style: TextStyle(
                        fontSize: 34.0,
                        fontFamily: "Explora",
                        color: Colors.white,
                        fontWeight: FontWeight.w900),
                  ),
                ],
              ),
              p1(),p2(), p3(), p5(),p6(),p4(),p7(),
              p8()


            ],
            )
            ],
            ),
            )


            ),
            );
            }
             }

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    将小部件包装在Align 小部件中

            Stack(
                  alignment: Alignment.center,
                  children: [
                    PageView(
                      controller:pageController,
                      children: [
                        Stack(
                          alignment: Alignment.center,
                          children: [
                            Image(image: AssetImage('Image/soc1.jpg'),
                              fit: BoxFit.cover,
                              width: 200,
                              height: 200),
                            const Text(' Hello world ',
                              style: TextStyle(
                                  fontSize: 34.0,
                                  fontFamily: "Explora",
                                  color: Colors.black,
                                  fontWeight: FontWeight.w900),
                            ),
                            Align(
                              alignment: Alignment.bottomLeft,
                              child: const Text(' Page 1 ',
                                style: TextStyle(
                                    fontSize: 34.0,
                                    fontFamily: "Explora",
                                    color: Colors.black,
                                    fontWeight: FontWeight.w900),
                              ),
                            ),
                          ],
                        ),
                      ],
                    )
                  ],
                ),
    

    【讨论】:

    • 你能否详细说明并解释我应该把对齐小部件放在哪里,因为我把它放在堆栈中它显示错误。
    • 你遇到了什么错误? p1 是一个小部件,对吗?如果是,那么您可以尝试使用 Align 包裹 p1
    • p1 p2 是带有不同引号的不同页面,overviewscreen 是主页,我只想在屏幕左下方显示一个页码。但是因为我有带有文本和图像的堆栈小部件,我无法计算如何在左下角编码..它只是显示错误(位置参数必须....命名参数等)
    • 已经更新我的代码,请尝试一下。在Stack 中使用Align 应该没问题,我已经尝试过了,它的工作原理
    猜你喜欢
    • 2021-12-23
    • 2019-11-25
    • 2021-10-12
    • 2021-03-13
    • 1970-01-01
    • 2021-10-02
    • 2019-11-12
    • 2022-09-24
    • 2019-04-09
    相关资源
    最近更新 更多