Flutter中不使用textAlign属性手动定位文本的方法咨询
问题:在背景图指定位置放置文本(不使用textAlign属性)
我正在使用Android Studio(Hedgehog版本)进行Flutter开发,需求是在背景图的指定位置上放置文本,但不想使用textAlign属性。我尝试过使用Alignment属性,效果不错,但大量搜索后仍未找到无需依赖textAlign属性来定位文本的相关资料。
以下是我使用textAlign属性实现的代码:
import 'package:flutter/material.dart'; void main() { runApp(RunMyApp()); } class RunMyApp extends StatelessWidget { const RunMyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, theme: ThemeData(primarySwatch: Colors.green), home: Scaffold( // appBar: AppBar( // title: Text("Text Over Image"), // ), body: Center( child: Stack( children: [ Container( alignment: Alignment.center, child: Image.asset( 'assets/bckground6.png', height: double.infinity, width: double.infinity, fit: BoxFit.cover, ), ), Container( alignment: Alignment.topCenter, child: Text( 'Text Over the Image', style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 24.0), )), ], ), ), ) , ); } }
项目树结构:
pubspec.yaml配置:
我搜索过textAlign属性的替代方案,但找到的资料大多仍在使用textAlign属性,查阅官方文档也只看到Align属性。
内容的提问来源于stack exchange,提问作者Xeyad
相关产品推荐
相关产品推荐

