Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振:如何使BoxShadow溢出兄弟小部件?_Flutter_Flutter Layout - Fatal编程技术网

Flutter 颤振:如何使BoxShadow溢出兄弟小部件?

Flutter 颤振:如何使BoxShadow溢出兄弟小部件?,flutter,flutter-layout,Flutter,Flutter Layout,我有一个行,其中有两个扩展的小部件作为其子项。因此,子级之间没有空格/填充。每个子级都包含一个容器(带有方框装饰),而该容器又包含一个扁平按钮。当突出显示FlatButton时,容器周围会出现一个BoxShadow 对于第二个按钮,阴影看起来很好,溢出了第一个按钮的一部分。但是,当突出显示第一个按钮时,BoxShadow的右侧(应该位于第二个按钮上方)会被剪裁。我认为这是因为第二个按钮(及其各自的祖先)位于小部件树中第一个按钮之后,因此是“更高的” 下面是我制作的DartPad实例,用于演示该问

我有一个
,其中有两个
扩展的
小部件作为其子项。因此,子级之间没有空格/填充。每个子级都包含一个
容器
(带有方框装饰),而该容器又包含一个
扁平按钮
。当突出显示
FlatButton
时,
容器周围会出现一个
BoxShadow

对于第二个按钮,阴影看起来很好,溢出了第一个按钮的一部分。但是,当突出显示第一个按钮时,
BoxShadow
的右侧(应该位于第二个按钮上方)会被剪裁。我认为这是因为第二个按钮(及其各自的祖先)位于小部件树中第一个按钮之后,因此是“更高的”

下面是我制作的DartPad实例,用于演示该问题:

我的问题本质上是如何实现,在完全相同的布局下,即按钮之间没有空间,每个按钮的阴影出现在另一个按钮上。即示例中“Button1”的阴影与“Button2”的阴影相同


谢谢

您好,您可以检查编辑的代码

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Generated App',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
        primaryColor: const Color(0xFF2196f3),
        accentColor: const Color(0xFF2196f3),
        canvasColor: const Color(0xFFfafafa),
      ),
      home: new MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);
  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('App Name'),
      ),
      body: new Container(
        child: Padding(
            padding: EdgeInsets.symmetric(horizontal: 10),
            child: Center(
                child: new Row(
              children: [
                Expanded(
                    child: Container(
                  color: Colors.white,
                  child: Padding(
                    padding: const EdgeInsets.fromLTRB(0, 0, 5, 0),
                    child: Container(
                        decoration: BoxDecoration(boxShadow: [
                          BoxShadow(
                            color: Colors.transparent,
                            blurRadius: 5.0,
                          ),
                        ]),
                        child: TestButton("Button1")),
                  ),
                )),
                Expanded(
                    child: Container(
                  color: Colors.white,
                  child: Padding(
                    padding: const EdgeInsets.fromLTRB(0, 0, 5, 0),
                    child: Container(
                        decoration: BoxDecoration(boxShadow: [
                          BoxShadow(
                            color: Colors.transparent,
                            blurRadius: 5.0,
                          ),
                        ]),
                        child: TestButton("Button2")),
                  ),
                ))
              ],
              mainAxisAlignment: MainAxisAlignment.start,
              mainAxisSize: MainAxisSize.max,
              crossAxisAlignment: CrossAxisAlignment.center,
            ))),
        padding: const EdgeInsets.all(0.0),
        alignment: Alignment.center,
      ),
    );
  }
}

class TestButton extends StatefulWidget {
  @required
  final String title;

  TestButton(this.title);

  @override
  _TestButtonState createState() => _TestButtonState();
}

class _TestButtonState extends State<TestButton> {
  bool isHighlighted = false;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        height: 50,
        decoration: BoxDecoration(boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(isHighlighted ? 0.5 : 0.0),
            spreadRadius: isHighlighted ? 5 : 0,
          )
        ]),
        child: FlatButton(
          shape: ContinuousRectangleBorder(borderRadius: BorderRadius.zero),
          splashColor: Colors.black12,
          color: Colors.white,
          hoverColor: Colors.black12,
          highlightColor: Colors.black12,
          mouseCursor: MouseCursor.uncontrolled,
          child: Text(widget.title),
          onPressed: () => null,
          onHighlightChanged: (value) {
            setState(() {
              isHighlighted = value;
            });
          },
        ));
  }

  @override
  void dispose() {
    super.dispose();
  }
}
导入“包装:颤振/材料.省道”;
导入“package:flatter/rendering.dart”;
void main(){
runApp(新的MyApp());
}
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回新材料PP(
标题:“生成的应用程序”,
主题:新主题数据(
主样本:颜色。蓝色,
原色:常量颜色(0xFF2196f3),
accentColor:const Color(0xFF2196f3),
画布颜色:常量颜色(0xFFFAFA),
),
主页:新建MyHomePage(),
);
}
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key}):超级(Key:Key);
@凌驾
_MyHomePageState createState()=>new_MyHomePageState();
}
类_MyHomePageState扩展状态{
@凌驾
小部件构建(构建上下文){
归还新脚手架(
appBar:新的appBar(
标题:新文本(“应用程序名称”),
),
主体:新容器(
孩子:填充(
填充:边缘组。对称(水平:10),
儿童:中心(
孩子:新的一排(
儿童:[
扩大(
子:容器(
颜色:颜色,白色,
孩子:填充(
padding:const EdgeInsets.fromLTRB(0,0,5,0),
子:容器(
装饰:BoxEdition(boxShadow:[
箱形阴影(
颜色:颜色。透明,
半径:5.0,
),
]),
子项:TestButton(“Button1”),
),
)),
扩大(
子:容器(
颜色:颜色,白色,
孩子:填充(
padding:const EdgeInsets.fromLTRB(0,0,5,0),
子:容器(
装饰:BoxEdition(boxShadow:[
箱形阴影(
颜色:颜色。透明,
半径:5.0,
),
]),
子项:TestButton(“Button2”),
),
))
],
mainAxisAlignment:mainAxisAlignment.start,
mainAxisSize:mainAxisSize.max,
crossAxisAlignment:crossAxisAlignment.center,
))),
填充:常量边集全部(0.0),
对齐:对齐.center,
),
);
}
}
类TestButton扩展StatefulWidget{
@必需的
最后的字符串标题;
TestButton(this.title);
@凌驾
_TestButtonState createState()=>\u TestButtonState();
}
类_TestButtonState扩展状态{
bool isHighlighted=错误;
@凌驾
void initState(){
super.initState();
}
@凌驾
小部件构建(构建上下文){
返回容器(
身高:50,
装饰:BoxEdition(boxShadow:[
箱形阴影(
颜色:颜色。黑色。不透明度(isHighlighted?0.5:0.0),
扩展半径:isHighlighted?5:0,
)
]),
孩子:扁平按钮(
形状:连续矩形边框(边框半径:borderRadius.zero),
颜色:颜色。黑色12,
颜色:颜色,白色,
hoverColor:Colors.black12,
highlightColor:Colors.black12,
mouseCursor:mouseCursor.uncontrolled,
子:文本(widget.title),
onPressed:()=>null,
onHighlightChanged:(值){
设置状态(){
isHighlighted=值;
});
},
));
}
@凌驾
无效处置(){
super.dispose();
}
}

您好,您可以检查编辑的代码

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Generated App',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
        primaryColor: const Color(0xFF2196f3),
        accentColor: const Color(0xFF2196f3),
        canvasColor: const Color(0xFFfafafa),
      ),
      home: new MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);
  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('App Name'),
      ),
      body: new Container(
        child: Padding(
            padding: EdgeInsets.symmetric(horizontal: 10),
            child: Center(
                child: new Row(
              children: [
                Expanded(
                    child: Container(
                  color: Colors.white,
                  child: Padding(
                    padding: const EdgeInsets.fromLTRB(0, 0, 5, 0),
                    child: Container(
                        decoration: BoxDecoration(boxShadow: [
                          BoxShadow(
                            color: Colors.transparent,
                            blurRadius: 5.0,
                          ),
                        ]),
                        child: TestButton("Button1")),
                  ),
                )),
                Expanded(
                    child: Container(
                  color: Colors.white,
                  child: Padding(
                    padding: const EdgeInsets.fromLTRB(0, 0, 5, 0),
                    child: Container(
                        decoration: BoxDecoration(boxShadow: [
                          BoxShadow(
                            color: Colors.transparent,
                            blurRadius: 5.0,
                          ),
                        ]),
                        child: TestButton("Button2")),
                  ),
                ))
              ],
              mainAxisAlignment: MainAxisAlignment.start,
              mainAxisSize: MainAxisSize.max,
              crossAxisAlignment: CrossAxisAlignment.center,
            ))),
        padding: const EdgeInsets.all(0.0),
        alignment: Alignment.center,
      ),
    );
  }
}

class TestButton extends StatefulWidget {
  @required
  final String title;

  TestButton(this.title);

  @override
  _TestButtonState createState() => _TestButtonState();
}

class _TestButtonState extends State<TestButton> {
  bool isHighlighted = false;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        height: 50,
        decoration: BoxDecoration(boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(isHighlighted ? 0.5 : 0.0),
            spreadRadius: isHighlighted ? 5 : 0,
          )
        ]),
        child: FlatButton(
          shape: ContinuousRectangleBorder(borderRadius: BorderRadius.zero),
          splashColor: Colors.black12,
          color: Colors.white,
          hoverColor: Colors.black12,
          highlightColor: Colors.black12,
          mouseCursor: MouseCursor.uncontrolled,
          child: Text(widget.title),
          onPressed: () => null,
          onHighlightChanged: (value) {
            setState(() {
              isHighlighted = value;
            });
          },
        ));
  }

  @override
  void dispose() {
    super.dispose();
  }
}
导入“包装:颤振/材料.省道”;
导入“package:flatter/rendering.dart”;
void main(){
runApp(新的MyApp());
}
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回新材料PP(
标题:“生成的应用程序”,
主题:新主题数据(
主样本:颜色。蓝色,
原色:常量颜色(0xFF2196f3),
accentColor:const Color(0xFF2196f3),
画布颜色:常量颜色(0xFFFAFA),
),
主页:新建MyHomePage(),
);
}
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key}):超级(Key:Key);
@凌驾
_MyHomePageState createState()=>new_MyHomePageState();
}
类_MyHomePageState扩展状态{
@凌驾
小部件构建(构建上下文){
归还新脚手架(
appBar:新的appBar(
标题:新文本(“应用程序名称”),
),
主体:新容器(
孩子:填充(
填充:边集。对称(水平)