【问题标题】:How to add a Strikethrough to Icon in Flutter?如何在 Flutter 中为图标添加删除线?
【发布时间】:2020-12-08 05:14:12
【问题描述】:

我需要在我的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,
),
)

它不工作

【问题讨论】:

  • @someuser 不工作
  • 它正在工作......

标签: flutter strikethrough


【解决方案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),
      ),
    );
  }
}

【讨论】:

  • 我忘记使用资产了。谢谢
猜你喜欢
  • 2019-10-02
  • 2023-03-20
  • 2020-01-16
  • 2023-01-31
  • 2011-05-23
  • 1970-01-01
  • 1970-01-01
  • 2020-01-13
  • 1970-01-01
相关资源
最近更新 更多