Как добавить собственный зачеркнутый текст в виджет текста во флаттере - PullRequest
1 голос
/ 15 мая 2019

Я ищу способ добавить пользовательский зачеркнутый текст в виджет, как показано ниже

enter image description here

Я смотрел на API стиля текста, ноНе удалось найти ни одной опции для настройки графического изображения Strikethrough.

Стиль: TextStyle (украшение: TextDecoration.lineThrough),

1 Ответ

1 голос
/ 15 мая 2019

как опция

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: StrikeThroughWidget(
            child: Text('Apple Juice', style: TextStyle(fontSize: 30)),
          ),
        ),
      ),
    );
  }
}

class StrikeThroughWidget extends StatelessWidget {
  final Widget _child;

  StrikeThroughWidget({Key key, @required Widget child})
      : this._child = child,
        super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: _child,
      padding: EdgeInsets.symmetric(horizontal: 8), // this line is optional to make strikethrough effect outside a text
      decoration: BoxDecoration(
        image: DecorationImage(image: AssetImage('graphics/strikethrough.png'), fit: BoxFit.fitWidth),
      ),
    );
  }
}

результат enter image description here

и зачеркнутое изображение enter image description here

...