Flutter:添加图像



我想在结果之前添加图像。我在pubspec.yaml中添加

  • 资产/图像/

Image.asset("assets/images/mark.png"(写在哪里?

有什么办法吗?

result.dart

import 'package:flutter/material.dart';
class Results extends StatefulWidget {
final int total, correct, incorrect, notattempted;
Results({this.incorrect, this.total, this.correct, this.notattempted});

@override
_ResultsState createState() => _ResultsState();
}

class _ResultsState extends State<Results> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text("${widget.correct}/ ${widget.total}", style: TextStyle(fontSize: 25),),
SizedBox(height: 5,),
Container(
padding: EdgeInsets.symmetric(horizontal: 24),
child: Text(
"you answered ${widget.correct} answers correctly and ${widget.incorrect} answeres incorrectly",
textAlign: TextAlign.center,),

),
SizedBox(height: 24,),
GestureDetector(
onTap: (){
Navigator.pop(context);
},
child: Container(
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 8),
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(30)
),
child: Text("Go to home", style: TextStyle(color: Colors.white, fontSize: 19),),
),
)
],),
),
),
);
}
}

有什么办法吗?如果你想看代码,请让我知道我会更新更多。

我不知道结果前的图像是什么意思。您的意思是将图片添加为列下显示的第一个项目吗?

import 'package:flutter/material.dart';
class Results extends StatefulWidget {
final int total, correct, incorrect, notattempted;
Results({this.incorrect, this.total, this.correct, this.notattempted});
@override
_ResultsState createState() => _ResultsState();
}
class _ResultsState extends State<Results> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Image.asset('assets/images/mark.png'),
Text("${widget.correct}/ ${widget.total}", style: TextStyle(fontSize: 25),),
SizedBox(height: 5,),
Container(
padding: EdgeInsets.symmetric(horizontal: 24),
child: Text(
"you answered ${widget.correct} answers correctly and ${widget.incorrect} answeres incorrectly",
textAlign: TextAlign.center,),
),
SizedBox(height: 24,),
GestureDetector(
onTap: (){
Navigator.pop(context);
},
child: Container(
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 8),
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(30)
),
child: Text("Go to home", style: TextStyle(color: Colors.white, fontSize: 19),),
),
)
],),
),
),
);
}
}

有关资产图像的更多详细信息,请点击此处。

使用Column小部件包装Results类。并在Results类中添加之前的图像。

相关内容

  • 没有找到相关文章

最新更新