Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.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 如何在颤振中设置浮动动作按钮的自定义位置?_Flutter_Flutter Layout - Fatal编程技术网

Flutter 如何在颤振中设置浮动动作按钮的自定义位置?

Flutter 如何在颤振中设置浮动动作按钮的自定义位置?,flutter,flutter-layout,Flutter,Flutter Layout,我正在尝试复制sportify,我想设置一个浮动操作按钮 有什么帮助吗?试试这个 class PlayerScreen extends StatelessWidget { const PlayerScreen({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Scaffold( body: CustomScrollView( p

我正在尝试复制sportify,我想设置一个浮动操作按钮 有什么帮助吗?

试试这个

class PlayerScreen extends StatelessWidget {
  const PlayerScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        physics: const BouncingScrollPhysics(
            parent: AlwaysScrollableScrollPhysics()),
        slivers: <Widget>[
          SliverAppBar(
            stretch: true,
            onStretchTrigger: () {
              // Function callback for stretch
              return Future<void>.value();
            },
            expandedHeight: 300.0,
            flexibleSpace: FlexibleSpaceBar(
              stretchModes: const <StretchMode>[
                StretchMode.zoomBackground,
                StretchMode.blurBackground,
                StretchMode.fadeTitle,
              ],
              centerTitle: true,
              title: FloatingActionButton(
                child: Icon(
                  Icons.play_arrow,
                  size: 30,
                ),
                onPressed: () {},
                backgroundColor: Colors.greenAccent[400],
              ),
              background: Stack(
                fit: StackFit.expand,
                children: <Widget>[
                  Image.network(
                    'https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg',
                    fit: BoxFit.cover,
                  ),
                  const DecoratedBox(
                    decoration: BoxDecoration(
                      gradient: LinearGradient(
                        begin: Alignment(0.0, 0.5),
                        end: Alignment.center,
                        colors: <Color>[
                          Color(0x60000000),
                          Color(0x00000000),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
          SliverList(
            delegate: SliverChildBuilderDelegate((ctx, index) {
              return ListTile(
                leading: Icon(Icons.wb_sunny),
                title: Text('Song $index'),
                subtitle: Text("description"),
              );
            }, childCount: 20),
          ),
        ],
      ),
    );
  }
}
class PlayerScreen扩展了小部件{
常量播放器屏幕({Key?Key}):超级(Key:Key);
@凌驾
小部件构建(构建上下文){
返回脚手架(
正文:自定义滚动视图(
物理学:康斯特弹跳克罗尔物理学(
父项:AlwaysScrollableScrollPhysics()),
条子:[
滑杆(
是的,
onStretchTrigger:(){
//用于拉伸的函数回调
返回Future.value();
},
扩展高度:300.0,
flexibleSpace:FlexibleSpaceBar(
横模:常数[
StretchMode.zoomBackground,
StretchMode.blurBackground,
StretchMode.fadeTitle,
],
标题:对,
标题:浮动操作按钮(
子:图标(
图标。播放箭头,
尺码:30,
),
按下:(){},
背景颜色:颜色。绿色口音[400],
),
背景:堆栈(
fit:StackFit.expand,
儿童:[
图像网络(
'https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg',
适合:BoxFit.cover,
),
常数装饰盒(
装饰:盒子装饰(
梯度:线性梯度(
开始:对齐(0.0,0.5),
结束:对齐。中间,
颜色:[
颜色(0x60000000),
颜色(0x00000000),
],
),
),
),
],
),
),
),
银表(
代表:SliverChildBuilderDelegate((ctx,索引){
返回列表块(
领先:图标(Icons.wb_sunny),
标题:文本(“歌曲$index”),
副标题:文本(“说明”),
);
},儿童人数:20),
),
],
),
);
}
}

您可以通过
Align
小部件将浮动操作按钮置于自定义位置吗

例如:

 Align(
         alignment: Alignment.center,
         child: FloatingActionButton(),
      ),

你可以通过Chang
center
word

获得更具体的位置。我个人不会在这里使用浮动操作按钮,而是使用带有按钮子级的堆栈。