我在TextStyle中搜索了陰影選項,但是我沒有找到。所以我問:我怎麼能給撲動的文字添加陰影?可能嗎? 例子:我如何向撲動的文字添加陰影?
new Text(
"asd"
styel: new TextStyle(
//add shadow?
));
我在TextStyle中搜索了陰影選項,但是我沒有找到。所以我問:我怎麼能給撲動的文字添加陰影?可能嗎? 例子:我如何向撲動的文字添加陰影?
new Text(
"asd"
styel: new TextStyle(
//add shadow?
));
撲不提供內置的文本陰影支持,但如果你不想等待issue 3402是固定的,這是可能的僞造陰影使用BackdropFilter
。
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
home: new MyApp(),
));
}
class ShadowText extends StatelessWidget {
ShadowText(this.data, { this.style }) : assert(data != null);
final String data;
final TextStyle style;
Widget build(BuildContext context) {
return new ClipRect(
child: new Stack(
children: [
new Positioned(
top: 2.0,
left: 2.0,
child: new Text(
data,
style: style.copyWith(color: Colors.black.withOpacity(0.5)),
),
),
new BackdropFilter(
filter: new ui.ImageFilter.blur(sigmaX: 2.0, sigmaY: 2.0),
child: new Text(data, style: style),
),
],
),
);
}
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Container(
child: new Center(
child: new ShadowText(
'Hello world!',
style: Theme.of(context).textTheme.display3,
),
),
),
);
}
}
或者,如果你不關心模糊,只是做了一些一些半透明Text
部件堆疊不太精確彼此的頂部Stack
。
非常感謝你,這是非常好的代碼:) – ZeroProcess