【问题标题】:Re-positioning of TextButton in Flutter在 Flutter 中重新定位 TextButton
【发布时间】:2021-07-18 19:57:25
【问题描述】:

我是 Flutter 新手,并且正在处理 Flutter 引导屏幕,我已经尝试了很多来重新定位文本按钮,但我无法做到这一点。

我希望文本按钮分别位于左下角和右下角,像这样

这是我的屏幕代码。

    import 'package:flutter/material.dart';
    import 'package:transformer_page_view/transformer_page_view.dart';

    class WalkThroughScreen extends StatefulWidget {
    final String title;
    WalkThroughScreen({this.title});
    @override
    WalkThroughScreenState createState() {
    return new WalkThroughScreenState();
    }
    }

    class WalkThroughScreenState extends State<WalkThroughScreen> {
    int _slideIndex = 0;

    final List<String> images = [
    "images/slide_1.png",
    "images/slide_2.png",
    "images/slide_3.png"
    ];

    final List<String> text1 = [
    "Snap the ultimate pictures",
    "Sync all Your Favourite Images & Videos",
    "Easily access Your Items on PC"
    ];
    final List<String> text0 = [
    "You will be able to create a folder, take as many pictures as you want, it will be 
    automatically stored in that folder",
    "All your images and videos will be automatically uploaded to a drive, when the WiFi network 
    is available",
    "You will be able to download the exact copies of the folders that you have stored on the 
    Phone"
    ];

    final IndexController controller = IndexController();

    @override
    Widget build(BuildContext context) {
    TransformerPageView transformerPageView = TransformerPageView(
    pageSnapping: true,
    onPageChanged: (index) {
    setState(() {
    this._slideIndex = index;
    });
        },
        loop: false,
        controller: controller,
        transformer: new PageTransformerBuilder(
            builder: (Widget child, TransformInfo info) {
          return new Material(
            color: Colors.white,
            elevation: 8.0,
            textStyle: new TextStyle(color: Colors.white),
            borderRadius: new BorderRadius.circular(12.0),
            child: new Container(
              alignment: Alignment.center,
              color: Colors.white,
              child: Padding(
                padding: const EdgeInsets.all(18.0),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    new ParallaxContainer(
                      child: CircleAvatar(
                        radius: 150.0,
                        backgroundColor: Colors.lightBlueAccent,
                        child: new Image.asset(
                          images[info.index],
                          fit: BoxFit.contain,
                          height: 350,
                        ),
                      ),
                      position: info.position,
                      translationFactor: 400.0,
                    ),
                    SizedBox(
                      height: 45.0,
                    ),
                    new ParallaxContainer(
                      child: new Text(
                        text1[info.index],
                        textAlign: TextAlign.center,
                        style: new TextStyle(
                          color: Colors.black,
                          fontSize: 27.0,
                          fontFamily: 'Segoe UI',
                          //fontWeight: FontWeight.bold
                        ),
                      ),
                      position: info.position,
                      translationFactor: 300.0,
                    ),
                    SizedBox(
                      height: 55.0,
                    ),
                    new ParallaxContainer(
                      child: new Text(
                        text0[info.index],
                        textAlign: TextAlign.center,
                        style: new TextStyle(
                          color: Colors.black,
                          fontSize: 20.0,
                          fontFamily: 'Segoe UI',
                          // fontWeight: FontWeight.bold
                        ),
                      ),
                      position: info.position,
                      opacityFactor: .8,
                      translationFactor: 400.0,
                    ),
                    SizedBox(
                      height: 45.0,
                    ),
                    new ParallaxContainer(
                        child: TextButton(
                          onPressed: () => print('Next'),
                          child: Text(
                            'Next',
                            style: TextStyle(
                              color: Colors.black,
                              fontSize: 20.0,
                              fontFamily: 'Segoe UI',
                            ),
                          ),
                        ),
                        position: info.position),
                    new ParallaxContainer(
                        child: TextButton(
                          onPressed: () => print('Skip'),
                          child: Text(
                            'Skip',
                            style: TextStyle(
                              color: Colors.black,
                              fontSize: 20.0,
                              fontFamily: 'Segoe UI',
                            ),
                          ),
                        ),
                        position: info.position)
                  ],
                ),
              ),
            ),
          );
        }),
        itemCount: 3);

    return Scaffold(
      backgroundColor: Colors.white,
      body: transformerPageView,
    );
  }
}

我正在尝试重新定位容器内的按钮,但由于我对颤振知之甚少,我无法做到这一点,如果有人可以请告诉我。

【问题讨论】:

    标签: flutter dart mobile


    【解决方案1】:

    您需要像这样将文本按钮包装在一行中:

          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              new ParallaxContainer(
                  child: TextButton(
                    onPressed: () => print('Skip'),
                    child: Text(
                      'Skip',
                      style: TextStyle(
                        color: Colors.black,
                        fontSize: 20.0,
                        fontFamily: 'Segoe UI',
                      ),
                    ),
                  ),
                  position: info.position),
              new ParallaxContainer(
                  child: TextButton(
                    onPressed: () => print('Next'),
                    child: Text(
                      'Next',
                      style: TextStyle(
                        color: Colors.black,
                        fontSize: 20.0,
                        fontFamily: 'Segoe UI',
                      ),
                    ),
                  ),
                  position: info.position),
            ],
          ),
    

    A Row 允许您将通过的子项水平放置在其中。 mainAxisAlignment: MainAxisAlignment.spaceBetween, 参数将所有剩余空间放置在两个按钮之间。 你可以找到关于颤振布局的综合指南here

    【讨论】:

      猜你喜欢
      • 2022-11-15
      • 2021-02-10
      • 2021-01-30
      • 2022-07-27
      • 2023-01-29
      • 2021-05-03
      • 1970-01-01
      • 2021-01-30
      • 2021-07-08
      相关资源
      最近更新 更多