Flutter:使用列表显示图标晶圆厂中的按钮不起作用



尝试使用FabCircularMenu包,我尝试使用List在FAB中显示图标。但是,该按钮没有显示任何内容。

List _fabBarIcons = [
FaIcon(FontAwesomeIcons.search),
FaIcon(FontAwesomeIcons.briefcase),
FaIcon(FontAwesomeIcons.users),
FaIcon(FontAwesomeIcons.calendar),
FaIcon(FontAwesomeIcons.cog),
];
...List.generate(
_fabBarIcons.length,
(index) {
Ink(
decoration: const ShapeDecoration(
color: Colors.cyan,
shape: CircleBorder(),
),
child: IconButton(
icon: _fabBarIcons[index],
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
),
);
return Container(
height: 0,
);
},
),

我试着添加颜色以使它看起来或其他东西。我在调试控制台上得到零错误。我不知道为什么这些图标按钮没有出现在这里。

您看不到任何内容,因为您正在从List.generate返回Container。相反,您应该返回Ink小部件。请参阅下面的代码:

import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: Test(),
),
),
);
}
}
class Test extends StatefulWidget {
@override
_TestState createState() => _TestState();
}
class _TestState extends State<Test> {
bool changeColor = false;
List _fabBarIcons = [
Icon(Icons.ac_unit),
Icon(Icons.access_time),
Icon(Icons.accessible),
Icon(Icons.ad_units),
Icon(Icons.search),
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Container(),
floatingActionButton: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(
_fabBarIcons.length,
(index) {
return Ink(
decoration: const ShapeDecoration(
color: Colors.cyan,
shape: CircleBorder(),
),
child: IconButton(
onPressed: () {},
icon: _fabBarIcons[index],
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
),
);
},
),
),
);
}
}

最新更新