如何在Flutter底部导航栏中使用SVG文件?

huangapple go评论76阅读模式
英文:

how to use svg file in bottom nav bar in flutter?

问题

  1. 将外部图标放入底部导航栏的正确方法是否只能使用SVG文件?
  2. 如果通过搜索理解类似问题1,那么我尝试了下面的代码,但只显示了文本标签,没有显示图标。如何解决?
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';

class HomePage extends StatelessWidget {
  
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 0.0,
        backgroundColor: Colors.transparent,
        leading: Icon(Icons.arrow_back_outlined),
        title: Text('MY ID Balance $298.98'),
        actions: [Icon(Icons.menu)],
      ),
      extendBodyBehindAppBar: true,
      body: Container(
        decoration: BoxDecoration(
          image: DecorationImage(
            fit: BoxFit.cover,
            image: AssetImage('assets/image/auth_background.png')
          )
        ),
      ),
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        items: <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            icon: SvgPicture.asset('assets/icons/bottomnav/menu.svg', width: 25, color: Colors.black),
            label: 'menu'
          ),
          BottomNavigationBarItem(
            icon: SvgPicture.asset('assets/icons/bottomnav/pfp.svg', color: Colors.black54, width: 30),
            label: 'pfp',
          ),
        ],
      )
    );
  }
}

如何在Flutter底部导航栏中使用SVG文件?

如何在Flutter底部导航栏中使用SVG文件?

如何在Flutter底部导航栏中使用SVG文件?

英文:
  1. Is it right the way to put external icon in bottomnavigationbar is only by svg file?
  2. if understand like question 1 through googling, so I tried like below code but it appers just label from text, no apper icon. How can I resolve it?
import &#39;package:flutter/material.dart&#39;;
import &#39;package:flutter_svg/svg.dart&#39;;

class HomePage extends StatelessWidget {
  
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 0.0,
        backgroundColor: Colors.transparent,
        leading: Icon(Icons.arrow_back_outlined),
         title: Text (&#39;MY ID Balance \$298.98&#39;),
        actions: [Icon(Icons.menu)],
      ),
      extendBodyBehindAppBar: true,
      body: Container(
        decoration: BoxDecoration(
            image: DecorationImage(
                fit: BoxFit.cover,
                image: AssetImage(&#39;assets/image/auth_background.png&#39;)
            )
        ),

      ),
      bottomNavigationBar:
    BottomNavigationBar(
    type: BottomNavigationBarType.fixed,
    items: &lt;BottomNavigationBarItem&gt;[
    BottomNavigationBarItem(
    icon: SvgPicture.asset(&#39;assets/icons/bottomnav/menu.svg&#39;, width: 25, color: Colors.black,),
    label: &#39;menu&#39;
    ),
    BottomNavigationBarItem(
    icon: SvgPicture.asset(&#39;assets/icons/bottomnav/pfp.svg&#39;, color: Colors.black54, width: 30),
    label: &#39;pfp&#39;,
    ),
   
    
    ],
    )

    );
  }
}



如何在Flutter底部导航栏中使用SVG文件?

如何在Flutter底部导航栏中使用SVG文件?

如何在Flutter底部导航栏中使用SVG文件?

答案1

得分: 1

不是所有的SVG都受到此软件包的支持。

您的SVG可能不受支持。通过运行以下代码片段进行验证,

final SvgParser parser = SvgParser();
try {
  parser.parse('assets/icons/bottomnav/menu.svg', warningsAsErrors: true);
  print('SVG is supported');
} catch (e) {
  print('SVG contains unsupported features');
}
英文:

Not all SVGs are supported by this package.

Your SVG is probably not supported. Verify by running this snippet,

final SvgParser parser = SvgParser();
try {
  parser.parse(&#39;assets/icons/bottomnav/menu.svg&#39;, warningsAsErrors: true);
  print(&#39;SVG is supported&#39;);
} catch (e) {
  print(&#39;SVG contains unsupported features&#39;);
}

huangapple
  • 本文由 发表于 2023年1月8日 22:34:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75048591.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定