简体   繁体   English

在 flutter 中使用带有列的扩展小部件

[英]Using Expanded widget with Column in flutter

im trying to use Expanded widget inside Column, i have tried various methods but nothing seems to be working!我试图在 Column 中使用 Expanded 小部件,我尝试了各种方法,但似乎没有任何效果!

so far i have been successfully built this:到目前为止,我已经成功构建了这个:

The image图片

but as it shows, the listview that i have put inside Expanded widget goes under the other widgets,(and the expanded widget is scrolling but the widget on top is in a fixed position) and i tried to put the expanded widget inside another column, and also tried to put the both into separate Expanded widgets, but nothing seems to be working,但正如它所显示的那样,我放在 Expanded 小部件中的列表视图位于其他小部件下方,(并且展开的小部件正在滚动,但顶部的小部件处于固定位置),我试图将展开的小部件放在另一列中,并且还尝试将两者放入单独的扩展小部件中,但似乎没有任何效果,

i really appreciate your help我真的很感谢你的帮助

here is my code that generates the image above:这是我生成上面图像的代码:

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;
                        });
                      },
                    ),
                  ],
                ),
              ),
            );
          },
        ),
      ),
    ],
  ),
);

} } } }

Currently your outer column is deciding that there's no scroll behavior.目前,您的外栏决定没有滚动行为。 You can wrap it with a SingleChildScrollable but then you'd face the problem of flexible children in a non flexible area.您可以用SingleChildScrollable将其包装起来,但随后您将面临非灵活区域中灵活子项的问题。 One solution that keeps your flexible layout is using a MediaQuery and just defining a large box as your flexible area:保持灵活布局的一种解决方案是使用 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'),
          );
        },
      ),
    ],
  ),
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM