代码之家  ›  专栏  ›  技术社区  ›  chichi

颤振:使用列表显示工厂中的图标按钮不起作用

  •  1
  • chichi  · 技术社区  · 4 年前

    FabCircularMenu 包和我试图显示图标在工厂内使用一个列表。但是,按钮没有显示任何内容。

     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,
                );
              },
            ),
    

    我试着添加颜色使它看起来或其他东西。我在调试控制台上没有错误。为什么这些图标没有显示出来。

    1 回复  |  直到 4 年前
        1
  •  1
  •   bluenile    4 年前

    您无法看到任何内容,因为您正在从返回容器列表生成. 相反,您应该返回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,
                  ),
                );
              },
            ),
          ),
        );
      }
    }