在列中使用扩展的窗口小部件

问题描述 投票:0回答:1

我试图在Column中使用Expanded窗口小部件,我尝试了各种方法,但似乎无济于事!

到目前为止,我已经成功地构建了这个:

The image

但是如图所示,我放入扩展小部件内的列表视图位于其他小部件下((并且扩展小部件正在滚动,但顶部的小部件处于固定位置)并且我尝试将展开的小部件放在另一列中,并且还尝试将两者放入单独的展开的小部件中,但似乎没有任何作用,

我非常感谢您的帮助

这是生成上面图像的代码:

import 'package:fluapp/constants.dart';
import 'package:fluapp/models/music_model.dart';
import 'package:fluapp/widgets/custom_button_widget.dart';
import 'package:fluapp/widgets/custom_progress_widget.dart';
import 'package:flutter/material.dart';

class PlayerPage extends StatefulWidget {
  @override
  _PlayerPageState createState() => _PlayerPageState();
}

class _PlayerPageState extends State<PlayerPage>
    with SingleTickerProviderStateMixin {
  List<MusicModel> _list;
  int _playid;
  var _value;
  AnimationController _controller;
  var isPlay;
  @override
  void initState() {
    _playid = 3;
    _list = MusicModel.list;
    _value = 0.0;
    _controller =
    AnimationController(vsync: this, duration: Duration(milliseconds: 250));
    isPlay = true;
    super.initState();
  }

  Widget build(BuildContext context) {
    return Scaffold(
  backgroundColor: AppColors.mainColor,
  body: Column(
    children: <Widget>[
      Padding(
        padding: const EdgeInsets.all(12),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            CustomButtonWidget(
              size: 50,
              onTap: () {
                Navigator.of(context).pop();
              },
              child: Icon(
                Icons.arrow_back,
                color: AppColors.styleColor,
              ),
            ),
            Text("PLAYING NOW",
                style: TextStyle(
                  color: AppColors.styleColor,
                  fontWeight: FontWeight.bold,
                )),
            CustomButtonWidget(
              size: 50,
              onTap: () {},
              child: Icon(
                Icons.menu,
                color: AppColors.styleColor,
              ),
            ),
          ],
        ),
      ),
      CustomButtonWidget(
        image: "assets/logo.jpg",
        size: MediaQuery.of(context).size.width * .7,
        borderWidth: 5,
        onTap: () {},
      ),
      Text(
        "Flume",
        style: TextStyle(
          color: AppColors.styleColor,
          fontSize: 32,
          fontWeight: FontWeight.bold,
          height: 2,
        ),
      ),
      Text(
        "Flume kucha",
        style: TextStyle(
          color: AppColors.styleColor.withAlpha(90),
          fontSize: 16,
          fontWeight: FontWeight.bold,
        ),
      ),
      Expanded(child: SizedBox()),
      Padding(
        padding: const EdgeInsets.symmetric(horizontal: 24),
        child: customProgressWidget(
          value: _value,
          labelStart: "1:21",
          labelEnd: "3:46",
        ),
      ),
      Expanded(child: SizedBox()),
      Padding(
        padding: const EdgeInsets.symmetric(horizontal: 42),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            CustomButtonWidget(
              size: 80,
              onTap: () {
                setState(() {
                  if (_value > .1) {
                    _value -= .1;
                  }
                });
              },
              child: Icon(
                Icons.fast_rewind,
                color: AppColors.styleColor,
              ),
              borderWidth: 5,
            ),
            CustomButtonWidget(
              size: 80,
              onTap: () {
                if (_controller.value == 0.0) {
                  _controller.forward();
                  setState(() {
                    isPlay = false;
                  });
                } else {
                  _controller.reverse();
                  setState(() {
                    isPlay = true;
                  });
                }
              },
              child: AnimatedIcon(
                icon: AnimatedIcons.pause_play,
                progress: _controller,
                color: isPlay ? Colors.white : AppColors.styleColor,
              ),
              borderWidth: 5,
              isActive: isPlay,
            ),
            CustomButtonWidget(
              size: 80,
              onTap: () {
                setState(() {
                  if (_value < .9) {
                    _value += .1;
                  }
                });
              },
              child: Icon(
                Icons.fast_forward,
                color: AppColors.styleColor,
              ),
              borderWidth: 5,
            ),
          ],
        ),
      ),
      SizedBox(height: 25),
//to here

      Expanded(
        child: ListView.builder(
          itemCount: _list.length,
          padding: EdgeInsets.all(5),
          itemBuilder: (context, index) {
            return GestureDetector(
              onTap: () {
                setState(() {
                  _playid = _list[index].id;
                });
              },
              child: Container(
                decoration: BoxDecoration(
                  color: _list[index].id == _playid
                      ? AppColors.activeColor
                      : AppColors.mainColor,
                  borderRadius: BorderRadius.all(
                    Radius.circular(20),
                  ),
                ),
                padding: EdgeInsets.all(16),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        Text(
                          _list[index].title,
                          style: TextStyle(
                            color: AppColors.styleColor,
                            fontSize: 16,
                          ),
                        ),
                        Text(
                          _list[index].album,
                          style: TextStyle(
                            color: AppColors.styleColor.withAlpha(90),
                            fontSize: 16,
                          ),
                        ),
                      ],
                    ),
                    CustomButtonWidget(
                      child: Icon(
                        _list[index].id == _playid
                            ? Icons.pause
                            : Icons.play_arrow,
                        color: _list[index].id == _playid
                            ? Colors.white
                            : AppColors.styleColor,
                      ),
                      size: 50,
                      isActive: _list[index].id == _playid,
                      onTap: () {
                        setState(() {
                          _playid = _list[index].id;
                        });
                      },
                    ),
                  ],
                ),
              ),
            );
          },
        ),
      ),
    ],
  ),
);

}}

flutter flutter-layout
1个回答
0
投票

当前,您的外栏正在确定没有滚动行为。您可以用SingleChildScrollable将其包装起来,但随后会遇到在非柔性区域中柔性子项的问题。保持灵活布局的一种解决方案是使用MediaQuery并仅将一个大框定义为灵活区域:

return Scaffold(
  body: ListView(
    children: [
      SizedBox(
        height: MediaQuery.of(context).size.height - 100,
        child: Column(
          children: [
            // Your flexible media player widgets
          ],
        ),
      ),
      ListView.builder(
        shrinkWrap: true,
        primary: false,
        itemCount: 10,
        itemBuilder: (_, __) {
          return ListTile(
            title: Text('song title'),
          );
        },
      ),
    ],
  ),
);
© www.soinside.com 2019 - 2024. All rights reserved.