简体   繁体   中英

Possible render error in Flutter DropdownButton

I'm working on a Spotify UI clon (the web version) on Flutter Web, and had implemented the top bar with the back/forward buttons and the user thing on the right, as a Column, but them realized that the bar is fixed on it's position, and that your music suggestions scroll through it.

My solution was to set a Stack with the bar on top, like so:

_mainScreen(BuildContext context){

    Size size = MediaQuery.of(context).size;

    return Container(
      padding: EdgeInsets.symmetric(horizontal: 15.0),
      color: Color.fromRGBO(22, 22, 22, 1.0),
      height: double.infinity,
      width: size.width*0.82,
      child: Stack(
        children: <Widget>[
          SingleChildScrollView(
            child: Column(
              children: <Widget>[
                SizedBox(height: size.height*0.09,),
                _suggestionLists(size)
              ],
            ),
          ),
          _topBar(size)
        ],
      )
    );
  }

And then this happened: That white line isn't supposed to be there

Neither it was there before making the changes I mentioned before. This is the code for that Widget:

_profileButtons(Size size){

    return Container(
      height: size.height*0.05,
      padding: EdgeInsets.symmetric(horizontal: 5.0),
      decoration: BoxDecoration(
        color: Color.fromRGBO(15, 15, 15, 0.8),
        borderRadius: BorderRadius.circular(100.0)
      ),
      child: DropdownButton<String>(
        dropdownColor: Color.fromRGBO(75, 75, 75, 1.0),
        style: TextStyle(color: Colors.white),
        hint: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Container(
              padding: EdgeInsets.all(1.0),
              child: Icon(Icons.person, color: Colors.white, size: 20,), 
              decoration: BoxDecoration(
                color: Color.fromRGBO(75, 75, 75, 1.0),
                border: Border.all(color: Color.fromRGBO(75, 75, 75, 1.0)),
                borderRadius: BorderRadius.circular(100.0)
                ),
            ),
            SizedBox(width: 5.0,),
            Text('Your UserName', style: TextStyle(color: Colors.white),),
          ],
        ),
        icon: Icon(Icons.arrow_drop_down, color: Colors.white,),
        items: <String>['Account', 'Profile', 'Log out'].map((String value) {
          return new DropdownMenuItem<String>(
            value: value,
            child: new Text(value),
          );
        }).toList(),
        onChanged: (_) {},
      )
    );
  }

I've tried messing up a bit with the container, borders, etc, but I don't seem to find what's wrong with it, could it be a render error? I'll provide extra code/details if required

You can copy paste run full code below
To hide underline, you can use DropdownButtonHideUnderline wrap DropdownButton
code snippet

DropdownButtonHideUnderline(
          child: DropdownButton<String>(

working demo

在此处输入图像描述

full code

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  _profileButtons(Size size) {
    return Container(
        height: size.height * 0.05,
        padding: EdgeInsets.symmetric(horizontal: 5.0),
        decoration: BoxDecoration(
            color: Color.fromRGBO(15, 15, 15, 0.8),
            borderRadius: BorderRadius.circular(100.0)),
        child: DropdownButtonHideUnderline(
          child: DropdownButton<String>(
            dropdownColor: Color.fromRGBO(75, 75, 75, 1.0),
            style: TextStyle(color: Colors.white),
            hint: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Container(
                  padding: EdgeInsets.all(1.0),
                  child: Icon(
                    Icons.person,
                    color: Colors.white,
                    size: 20,
                  ),
                  decoration: BoxDecoration(
                      color: Color.fromRGBO(75, 75, 75, 1.0),
                      border:
                          Border.all(color: Color.fromRGBO(75, 75, 75, 1.0)),
                      borderRadius: BorderRadius.circular(100.0)),
                ),
                SizedBox(
                  width: 5.0,
                ),
                Text(
                  'Your UserName',
                  style: TextStyle(color: Colors.white),
                ),
              ],
            ),
            icon: Icon(
              Icons.arrow_drop_down,
              color: Colors.white,
            ),
            items:
                <String>['Account', 'Profile', 'Log out'].map((String value) {
              return new DropdownMenuItem<String>(
                value: value,
                child: new Text(value),
              );
            }).toList(),
            onChanged: (_) {},
          ),
        ));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(appBar: AppBar(), body: _profileButtons(Size(800, 800)));
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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