首次启动应用程序时未加载SVG。仅在热重载后显示。我正在使用Flutter SVG库。我在有状态的小部件内包含SVG。代码有什么问题?我还添加了屏幕截图。看看!
之前:
之后:
class FirstPage extends StatefulWidget {
_FirstPageState createState() => _FirstPageState();
}
class _FirstPageState extends State<FirstPage> {
int height = 180;
Color maleCardColor = inactiveCardColor;
Color femaleCardColor = inactiveCardColor;
Gender selectedGender;
@override
Widget build(BuildContext context) {
return Container(
child: Padding(
padding: const EdgeInsets.fromLTRB(8.0, 30, 8.0, 0.0),
child: Column(
children: <Widget>[
appTitle(),
SizedBox(
height: 15.0,
),
Row(
children: <Widget>[
GestureDetector(
child: ReusableCard(
color: selectedGender == Gender.female
? activeCardColor
: inactiveCardColor,
cardChild: Column(
children: <Widget>[
SvgPicture.asset(
'assets/female.svg',
color: Colors.white,
),
SizedBox(
height: 15.0,
),
Text(
'FEMALE',
style: kCardDefaultText,
),
],
),
),
onTap: () {
setState(() {
selectedGender = Gender.female;
});
},
),