您好,请再次帮助我,我的浮动操作按钮不会显示在我放置的所有元素上,而是在页面底部。创建项目时,我检查了颤振的样板,但它的位置正确,但是我不会正确定位。
注意:我对此进行了搜索,但发现了
Stack
和Extended
的信息,但我不完全知道将它们放在哪里。谢谢!
这是我的代码:
import 'package:flutter/material.dart';
import 'package:vmembershipofficial/Widgets/afterintroducing.dart';
import 'package:vmembershipofficial/Widgets/discount_carousel.dart';
import 'package:vmembershipofficial/Widgets/header_carousel.dart';
import 'package:vmembershipofficial/Widgets/introducing_vmembership.dart';
class NavHome extends StatefulWidget {
// static final String id = 'homepage';
NavHome({Key key}) : super(key: key);
@override
_NavHomeState createState() => _NavHomeState();
}
class _NavHomeState extends State<NavHome> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: ListView(
children: <Widget>[
Padding(
padding: EdgeInsets.symmetric(horizontal: 30.0, vertical: 10.0),
child: Text(
"Explore V!",
style: TextStyle(fontWeight: FontWeight.w600, fontSize: 20.0),
),
),
SizedBox(height: 5.0),
HeaderCarousel(),
SizedBox(height: 30.0),
Padding(
padding: EdgeInsets.symmetric(horizontal: 30.0, vertical: 10.0),
child: Text(
"Discount",
style: TextStyle(fontWeight: FontWeight.w600, fontSize: 20.0),
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 30.0, vertical: 5.0),
child: Text(
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
style: TextStyle(fontSize: 12.0),
),
),
DiscountCarousel(),
SizedBox(height: 30.0),
Padding(
padding: EdgeInsets.symmetric(horizontal: 30.0, vertical: 10.0),
child: Text(
"Introducing V Membership Plus",
style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.w600),
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 30.0, vertical: 4.0),
child: Text(
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
style: TextStyle(fontSize: 12.0),
),
),
VmembershipPlus(),
SizedBox(height: 30.0),
Padding(
padding: EdgeInsets.symmetric(horizontal: 30.0, vertical: 10.0),
child: Text(
"Lorem Ipsum",
style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.w600),
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 30.0, vertical: 4.0),
child: Text(
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
style: TextStyle(fontSize: 12.0),
),
),
SizedBox(
height: 10.0,
),
AfterIntroducing(),
SizedBox(
height: 10.0,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 30.0),
child: FlatButton(
padding: EdgeInsets.all(15.0),
color: Colors.blue,
textColor: Colors.white,
onPressed: () {},
child: Text(
"LOREM IPSUM",
style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.w600),
),
),
),
SizedBox(
height: 50.0,
),
FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {},
)
],
),
),
);
}
}
答案 0 :(得分:1)
FloatActionButton应该放置在Scaffold中相同级别的应用栏或主体中
class _NavHomeState extends State<NavHome> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(),
FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {},
)
);
}
}
在flutter youtube channel或flutter docs中查看每个小部件的示例,您将知道如何将它们放在小部件树中。
您还可以检查FloatingActionButton class文档。
答案 1 :(得分:1)
只需将FloatingActionButton放在体外,但在脚手架小部件内即可。
如果将FloatingActionButton添加到Scaffold属性floatActionButton中,它将具有默认行为,
class _NavHomeState extends State<NavHome> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Your_Widget_Here(),
floatingActionButton : FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {},
)
);
}
}
答案 2 :(得分:0)
尝试一下:
import 'package:flutter/material.dart';
import 'package:vmembershipofficial/Widgets/afterintroducing.dart';
import 'package:vmembershipofficial/Widgets/discount_carousel.dart';
import 'package:vmembershipofficial/Widgets/header_carousel.dart';
import 'package:vmembershipofficial/Widgets/introducing_vmembership.dart';
class NavHome extends StatefulWidget {
// static final String id = 'homepage';
NavHome({Key key}) : super(key: key);
@override
_NavHomeState createState() => _NavHomeState();
}
class _NavHomeState extends State<NavHome> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: ListView(
children: <Widget>[
Padding(
padding: EdgeInsets.symmetric(horizontal: 30.0, vertical: 10.0),
child: Text(
"Explore V!",
style: TextStyle(fontWeight: FontWeight.w600, fontSize: 20.0),
),
),
SizedBox(height: 5.0),
HeaderCarousel(),
SizedBox(height: 30.0),
Padding(
padding: EdgeInsets.symmetric(horizontal: 30.0, vertical: 10.0),
child: Text(
"Discount",
style: TextStyle(fontWeight: FontWeight.w600, fontSize: 20.0),
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 30.0, vertical: 5.0),
child: Text(
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
style: TextStyle(fontSize: 12.0),
),
),
DiscountCarousel(),
SizedBox(height: 30.0),
Padding(
padding: EdgeInsets.symmetric(horizontal: 30.0, vertical: 10.0),
child: Text(
"Introducing V Membership Plus",
style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.w600),
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 30.0, vertical: 4.0),
child: Text(
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
style: TextStyle(fontSize: 12.0),
),
),
VmembershipPlus(),
SizedBox(height: 30.0),
Padding(
padding: EdgeInsets.symmetric(horizontal: 30.0, vertical: 10.0),
child: Text(
"Lorem Ipsum",
style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.w600),
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 30.0, vertical: 4.0),
child: Text(
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
style: TextStyle(fontSize: 12.0),
),
),
SizedBox(
height: 10.0,
),
AfterIntroducing(),
SizedBox(
height: 10.0,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 30.0),
child: FlatButton(
padding: EdgeInsets.all(15.0),
color: Colors.blue,
textColor: Colors.white,
onPressed: () {},
child: Text(
"LOREM IPSUM",
style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.w600),
),
),
),
SizedBox(
height: 50.0,
),
],
),
),
floatingActionButton : FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {},
)
);
}
}