flutter : flutter 图像上的文字
flutter : Text on image in flutter
我想在图片上写透明颜色的文字。像这样。
我想在图片上写文字,但无法正确完成。
这是我的代码。
我想在图片上写文字,但无法正确完成。
而且我还想要文本的透明颜色。
请帮助我。
import 'package:card_example/color_filters.dart';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
static final String title = 'Card Example';
@override
Widget build(BuildContext context) => MaterialApp(
debugShowCheckedModeBanner: false,
title: title,
theme: ThemeData(primarySwatch: Colors.deepOrange),
home: MainPage(title: title),
);
}
class MainPage extends StatefulWidget {
final String title;
const MainPage({
@required this.title,
});
@override
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: ListView(
padding: EdgeInsets.all(16),
children: [
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
child: Stack(
alignment: Alignment.center,
children: [
Ink.image(
image: NetworkImage(
'https://resources.pulse.icc-cricket.com/ICC/photo/2018/04/22/c19486c2-4e5b-48c4-82af-c6d0eebb7bd2/Main.jpg',
),
colorFilter: ColorFilters.greyscale,
child: InkWell(
onTap: () {},
),
height: 240,
fit: BoxFit.cover,
),
Text(
'Sachin Tendulkar',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 24,
),
),
],
),
)
],
),
);
}}
我想在图片上写文字,但无法正确完成。
而且我还想要文本的透明颜色。
请帮助我。
如果想用于该容器,并且我使用图像文本小部件装饰文本,那么如何使图像中的东西准确无误。
尝试将 bottomCenter
添加到 alignment
Stack(
alignment: Alignment.bottomCenter, //Here
children: [
Ink.image(
image: NetworkImage(
'https://static.remove.bg/remove-bg-web/3661dd45c31a4ff23941855a7e4cedbbf6973643/assets/start_remove-79a4598a05a77ca999df1dcb434160994b6fde2c3e9101984fb1be0f16d0a74e.png',
),
child: InkWell(
onTap: () {},
),
height: 240,
fit: BoxFit.cover,
),
Text(
'Sachin Tendulkar',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 24,
),
),
],
);
结果:
如果您考虑splashColor
,有多种方法可以解决这个问题:
在 Stack 中使用 Ink.image() 将不会提供 circular borderRadius
。检查 this GitHub issue. 是否仍处于打开状态。
ClipRRect(
borderRadius: BorderRadius.circular(12),
child: SizedBox(
width: 300,
height: 300,
child: Stack(
fit: StackFit.expand,
children: [
Align(
alignment: Alignment.bottomCenter,
child: Container(
width: double.infinity,
padding: EdgeInsets.all(8),
color: Colors.blue.withOpacity(.5),
child: Text(
'Sachin Tendulkar',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 24,
),
),
),
),
Ink.image(
image: NetworkImage(
'https://resources.pulse.icc-cricket.com/ICC/photo/2018/04/22/c19486c2-4e5b-48c4-82af-c6d0eebb7bd2/Main.jpg',
),
fit: BoxFit.cover,
child: InkWell(
borderRadius: BorderRadius.circular(12),
onTap: () {},
),
),
],
)),
);
1: 使用 GridTile
Container(
width: 300,
height: 300,
color: Colors.transparent,
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: InkWell(
onTap: () {},
child: GridTile(
child: Image.network(
'https://resources.pulse.icc-cricket.com/ICC/photo/2018/04/22/c19486c2-4e5b-48c4-82af-c6d0eebb7bd2/Main.jpg',
fit: BoxFit.cover,
),
footer: Container(
padding: EdgeInsets.all(8),
color: Colors.blue.withOpacity(.5),
child: Text(
'Sachin Tendulkar',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 24,
),
),
),
),
),
),
);
2:使用Container的修饰
InkWell(
onTap: () {},
splashColor: Colors.red,
child: Container(
width: 300,
height: 300,
alignment: Alignment.bottomCenter,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
image: DecorationImage(
image: NetworkImage(
'https://resources.pulse.icc-cricket.com/ICC/photo/2018/04/22/c19486c2-4e5b-48c4-82af-c6d0eebb7bd2/Main.jpg',
),
fit: BoxFit.cover,
),
),
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.blue.withOpacity(.5),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(12),
bottomRight: Radius.circular(12),
),
),
padding: EdgeInsets.all(8),
child: Text(
'Sachin Tendulkar',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 24,
),
),
),
),
);
我想在图片上写透明颜色的文字。像这样。
我想在图片上写文字,但无法正确完成。
这是我的代码。
我想在图片上写文字,但无法正确完成。 而且我还想要文本的透明颜色。 请帮助我。
import 'package:card_example/color_filters.dart';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
static final String title = 'Card Example';
@override
Widget build(BuildContext context) => MaterialApp(
debugShowCheckedModeBanner: false,
title: title,
theme: ThemeData(primarySwatch: Colors.deepOrange),
home: MainPage(title: title),
);
}
class MainPage extends StatefulWidget {
final String title;
const MainPage({
@required this.title,
});
@override
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: ListView(
padding: EdgeInsets.all(16),
children: [
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
child: Stack(
alignment: Alignment.center,
children: [
Ink.image(
image: NetworkImage(
'https://resources.pulse.icc-cricket.com/ICC/photo/2018/04/22/c19486c2-4e5b-48c4-82af-c6d0eebb7bd2/Main.jpg',
),
colorFilter: ColorFilters.greyscale,
child: InkWell(
onTap: () {},
),
height: 240,
fit: BoxFit.cover,
),
Text(
'Sachin Tendulkar',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 24,
),
),
],
),
)
],
),
);
}}
我想在图片上写文字,但无法正确完成。 而且我还想要文本的透明颜色。 请帮助我。
如果想用于该容器,并且我使用图像文本小部件装饰文本,那么如何使图像中的东西准确无误。
尝试将 bottomCenter
添加到 alignment
Stack(
alignment: Alignment.bottomCenter, //Here
children: [
Ink.image(
image: NetworkImage(
'https://static.remove.bg/remove-bg-web/3661dd45c31a4ff23941855a7e4cedbbf6973643/assets/start_remove-79a4598a05a77ca999df1dcb434160994b6fde2c3e9101984fb1be0f16d0a74e.png',
),
child: InkWell(
onTap: () {},
),
height: 240,
fit: BoxFit.cover,
),
Text(
'Sachin Tendulkar',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 24,
),
),
],
);
结果:
如果您考虑splashColor
,有多种方法可以解决这个问题:
在 Stack 中使用 Ink.image() 将不会提供 circular borderRadius
。检查 this GitHub issue. 是否仍处于打开状态。
ClipRRect(
borderRadius: BorderRadius.circular(12),
child: SizedBox(
width: 300,
height: 300,
child: Stack(
fit: StackFit.expand,
children: [
Align(
alignment: Alignment.bottomCenter,
child: Container(
width: double.infinity,
padding: EdgeInsets.all(8),
color: Colors.blue.withOpacity(.5),
child: Text(
'Sachin Tendulkar',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 24,
),
),
),
),
Ink.image(
image: NetworkImage(
'https://resources.pulse.icc-cricket.com/ICC/photo/2018/04/22/c19486c2-4e5b-48c4-82af-c6d0eebb7bd2/Main.jpg',
),
fit: BoxFit.cover,
child: InkWell(
borderRadius: BorderRadius.circular(12),
onTap: () {},
),
),
],
)),
);
1: 使用 GridTile
Container(
width: 300,
height: 300,
color: Colors.transparent,
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: InkWell(
onTap: () {},
child: GridTile(
child: Image.network(
'https://resources.pulse.icc-cricket.com/ICC/photo/2018/04/22/c19486c2-4e5b-48c4-82af-c6d0eebb7bd2/Main.jpg',
fit: BoxFit.cover,
),
footer: Container(
padding: EdgeInsets.all(8),
color: Colors.blue.withOpacity(.5),
child: Text(
'Sachin Tendulkar',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 24,
),
),
),
),
),
),
);
2:使用Container的修饰
InkWell(
onTap: () {},
splashColor: Colors.red,
child: Container(
width: 300,
height: 300,
alignment: Alignment.bottomCenter,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
image: DecorationImage(
image: NetworkImage(
'https://resources.pulse.icc-cricket.com/ICC/photo/2018/04/22/c19486c2-4e5b-48c4-82af-c6d0eebb7bd2/Main.jpg',
),
fit: BoxFit.cover,
),
),
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.blue.withOpacity(.5),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(12),
bottomRight: Radius.circular(12),
),
),
padding: EdgeInsets.all(8),
child: Text(
'Sachin Tendulkar',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 24,
),
),
),
),
);