flutter - 如何在颤动中将文本放在svg图像上
问题描述
我有一行包含两个 svg 图像和两个文本。我希望一些文字应该出现在 svg 图像上。请帮助我。提前谢谢你
final heading_register=new Container(
color: const Color(0xFF008000),
padding: const EdgeInsets.all(5.0),
child: Row(
children: <Widget>[
Stack(
children: <Widget>[
svgIcon,
Center(child: Text("1")),
]
),
Expanded(
child: Text('New Registartion',style: new TextStyle(color: Colors.white,fontWeight: FontWeight.bold,fontSize: 16.0),),
),
Stack(
children: <Widget>[
svgIcon,
Text("1",textAlign: TextAlign.end,),
]
),
Expanded(
child: Text('Total Registartion',style: new TextStyle(color: Colors.white,fontWeight: FontWeight.bold,fontSize: 16.0),),
),
],
),
);
解决方案
您可以将Stack小部件与alignment: Alignment.center
. Alignment.center
将所有孩子Stack
从其中心居中。
小的独立示例:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
static const String example = 'The quick brown fox jumps over the lazy dog';
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
IconWithText(text: 'Home', icon: Icons.home),
IconWithText(text: 'Car', icon: Icons.directions_car)
],
),
)
),
);
}
}
class IconWithText extends StatelessWidget {
final IconData icon;
final String text;
IconWithText({this.icon, this.text});
@override
Widget build(BuildContext context) {
return Stack(
alignment: Alignment.center,
children: <Widget>[
Icon(icon, color: Colors.red, size: 60.0,),
Text(text, style: TextStyle(fontSize: 30.0),)
],
);
}
}
推荐阅读
- python - 如何摆脱最后一列中的零
- amazon-web-services - 跨多个 EC2 实例的 buildManifest 上的 Nextjs 404s
- angular - How to resolve "Cannot read property 'map' of null" after npm start?
- swift - Swift:错误:在隐式展开可选值时意外发现 nil
- css - Angular ng-container 未显示值
- c# - c# 从 3d 位置、单位向量和维度获取对象的 2d 绘图点
- sql - SQL Case 当至少一个值等于 value 然后设置为 value
- python - 如何将实时音频实时馈送到 keras 模型?
- ruby-on-rails - 如何使设计不需要对主页进行身份验证?
- mysql - 使用 mysql.connector 连接到 MySQL 数据库时出错