2017-06-01 73 views

回答

3

撲不提供內置的文本陰影支持,但如果你不想等待issue 3402是固定的,這是可能的僞造陰影使用BackdropFilter

screenshot

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

+0

非常感謝你,這是非常好的代碼:) – ZeroProcess