【问题标题】:Align multiple button in center of flutter webpage在颤振网页中心对齐多个按钮
【发布时间】:2020-11-22 09:31:03
【问题描述】:

我正在尝试将页面的底部对齐到中心,这在移动设备上正确显示,但在网络中它看起来不正确。如何在页面中心排列所有 4 个音乐按钮和文本。我尝试了 Align friand center 但两者都没有将它们带到小部件的中心。我的目标是根据页面大小在页面中心获得一个按钮,如果页面大小在代码下方是好的,但是当我最大化浏览器时它不会显示在中心。

Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Container(
                  width: MediaQuery.of(context).size.width * 0.7,
                  // child: Expanded(child: slider()),
                  child: kIsWeb ? null : slider(),
                ),
                Marquee(
                  child: Text(inuseAudioinfo.title ?? appname,
                      softWrap: true,
                      style: TextStyle(
                        // color: AppColors.black.withAlpha(90),
                        color: AppColors.black.withAlpha(150),
                        fontSize: 16,
                      )),
                ),
                Container(
                  decoration: BoxDecoration(
                      border: Border(
                    top: BorderSide(color: Colors.red[300]),
                    // bottom: BorderSide(color: AppColors.white)
                  )),
                  child: Wrap(
                    spacing: kIsWeb
                        ? MediaQuery.of(context).size.width * 0.1
                        : 25, // space between two icons
                    children: <Widget>[
                      IconButton(
                        icon: Icon(
                          inuseAudioinfo.isRepeat
                              ? Icons.repeat_one
                              : Icons.repeat,
                          color: inuseAudioinfo.isRepeat
                              ? AppColors.brown
                              : AppColors.black,
                        ),
                        onPressed: () {
                          print("User clicked Repeat one.");
                          if (inuseAudioinfo.playId != null) {
                            Duration seekdur = new Duration(seconds: 10);
                            if (inuseAudioinfo.isRepeat) {
                              setState(() {
                                inuseAudioinfo.isRepeat = false;
                              });
                            } else {
                              setState(() {
                                inuseAudioinfo.isRepeat = true;
                              });
                            }
                          } else {
                            commonmethod.displayDialog(
                              context,
                              "",
                              "Please select song to play.",
                              Icon(
                                Icons.library_music,
                                size: 100,
                                color: AppColors.red200,
                              ),
                            );
                          }
                        },
                      ),
                      IconButton(
                          icon: Icon(
                            inuseAudioinfo.isPlaying
                                ? Icons.pause
                                : Icons.play_arrow,
                            color: AppColors.black,
                          ),
                          onPressed: () {
                            _player(_songId);
                          }),
                      IconButton(
                          icon: Icon(
                            Icons.stop,
                            color: AppColors.black,
                          ),
                          onPressed: () {
                            if (inuseAudioinfo.isPlaying) {
                              // _inuseAudioinfo.audioPlayer.stop();
                              inuseAudioinfo.duration =
                                  new Duration(seconds: 0);
                              inuseAudioinfo.audioPlayer.stop();
                              setState(() {
                                inuseAudioinfo.isPlaying = false;
                                // position = new Duration(seconds: 0);
                                // _duration = new Duration();
                              });
                            }

                            // isPlaying = false;
                          }),
                      IconButton(
                          icon: Icon(
                            Icons.shuffle,
                            color: inuseAudioinfo.isShuffle
                                ? AppColors.brown
                                : AppColors.black,
                          ),
                          onPressed: () {
                            if (inuseAudioinfo.isShuffle) {
                              setState(() {
                                inuseAudioinfo.isShuffle = false;
                              });
                            } else {
                              setState(() {
                                inuseAudioinfo.isShuffle = true;
                              });
                            }
                          }),
                    ],
                  ),
                ),
                // ),
                // ),
              ],
            )

【问题讨论】:

  • 你可以使用 align wedigt
  • 我尝试与容器对齐,但没有帮助。
  • 使用 spacer() else expand() 它可能对你有帮助:)
  • @ParthPitroda 它的实际浏览器大小会有所不同,在最大化大小上我看到了这种差异。正如你提到的,我添加了垫片,问题仍然存在,但有所帮助。

标签: flutter flutter-layout flutter-web


【解决方案1】:

删除 Wrap() 并使用 Row(mainAxisAlignment: MainAxisAlignment.center,)

【讨论】:

    猜你喜欢
    • 2019-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-16
    • 2014-07-19
    • 1970-01-01
    • 1970-01-01
    • 2020-05-26
    相关资源
    最近更新 更多