Как добавить зачеркивание к значку в Flutter?

#flutter #strikethrough

#flutter #зачеркивание

Вопрос:

Мне нужно добавить зачеркивание в моем icon . Я читал о пользовательском зачеркивании с использованием отступов, но он работает с текстом

 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),
  )
 

Как я могу добавить его в этот код?

 Icon(
 Icons.list_alt,
 color: Colors.white,
)
 

Редактировать 1

Я пытался :

 Container(
 padding: EdgeInsets.symmetric(horizontal: 8),
 child: Icon(
 Icons.shopping_cart,
 color: Colors.white,
 size: 200,
),
)
 

И это не работает

Комментарии:

1. @someuser не работает

2. это работает…

Ответ №1:

введите описание изображения здесь

 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: Icon(Icons.shopping_cart, color: Colors.orangeAccent, size: 200),
          ),
        ),
      ),
    );
  }
}

class StrikeThroughWidget extends StatelessWidget {
  final Widget child;

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

  @override
  Widget build(BuildContext context) {
    return Container(
      child: child,
      padding: EdgeInsets.symmetric(horizontal: 8),
      foregroundDecoration: BoxDecoration(
        image: DecorationImage(image: AssetImage('assets/strikethrough.png'), fit: BoxFit.fitWidth),
      ),
    );
  }
}
 

Комментарии:

1. Я забыл использовать ресурс. Спасибо