Flutter文本装饰插件strike的使用

发布于 1周前 作者 songsunli 来自 Flutter

Flutter文本装饰插件strike的使用

支持

Roadmap

  • ✅ 查找用户资料(通过handle)
  • ✅ 查找用户资料(通过ID)
  • ✅ 发布基本账单
  • ✅ 向特定接收者发布账单
  • ✅ 通过ID查找账单
  • ✅ 为账单发布报价
  • ✅ 取消未支付的账单
  • ✅ 获取货币汇率
  • ✅ 从账单打开Strike应用(移动端)
  • ✅ 从报价打开Strike应用(移动端)
  • ❌ 从账单打开Strike应用(网页端)
  • ❌ 从报价打开Strike应用(网页端)
  • ❌ 获取Webhook事件
  • ❌ 通过ID查找Webhook事件
  • ❌ 获取Webhook订阅
  • ❌ 创建新的Webhook订阅
  • ❌ 通过ID查找Webhook订阅
  • ❌ 更新Webhook订阅
  • ❌ 删除Webhook订阅

开始使用

为了使用Strike API,你需要请求一个API密钥。

安全保管API密钥

你可以使用flutter_dotenv包来安全地保存你的API密钥,避免将其暴露在公共仓库中。

  1. pubspec.yaml文件中添加flutter_dotenv
  2. *.env添加到项目.gitignore文件中
  3. 在项目的根目录下创建一个.env文件,并添加以下内容:
STRIKE_API_KEY=<YOUR_API_KEY>
  1. .env文件添加到pubspec.yaml的资源部分并运行flutter pub get
assets:
  - .env

使用

创建你的Strike实例。

不使用flutter_dotenv

Strike _strike = Strike(apiKey: '<YOUR_API_KEY>');

使用flutter_dotenv

await dotenv.load(fileName: '.env');

Strike _strike = Strike(apiKey:dotenv.env['STRIKE_API_KEY']!);

发布账单

发布账单时,只需要提供InvoiceAmount(包括数量和货币类型)。其他字段是可选的。

为自己发布账单

await strike.issueInvoice(
  handle: null,
  correlationId: null,
  description: null,
  invoiceAmount: InvoiceAmount(
     amount: 10,
     currency: CurrencyType.USD,
  ),
);

为他人发布账单

await strike.issueInvoice(
  handle: '<RECEIVER_HANDLE>',
  correlationId: null,
  description: "Nice work!",
  invoiceAmount: InvoiceAmount(
     amount: 1,
     currency: CurrencyType.BTC,
  ),
);

打开账单

Strike移动应用接受以下格式的深度链接:https://strike.me/pay/<INVOICE_ID>

OutlinedButton(
  child: const Text('Open Strike App'),
  onPressed: () {
   invoice?.openStrikeApp(); // launchUrl(Uri.parse('https://strike.me/pay/$invoiceId'));
  },
),

取消未支付的账单

Invoice? cancelledInvoice = await strike.cancelUnpaidInvoice(invoiceId: invoice?.invoiceId);

发布报价

一旦你有一个账单,你可以生成一个报价。

strike.issueQuoteForInvoice(invoiceId: invoice.invoiceId)

打开报价

URL方案用于闪电网络支付是 "lightning:<LIGHTNING_INVOICE>"

OutlinedButton(
  child: const Text('Open Strike'),
  onPressed: () {
   quote.openStrikeApp(); // launchUrl(Uri.parse('lightning:$lnInvoice'));
  },
),

生成报价的二维码

每个报价都包含一个“lnInvoice”字段,它是编码后的闪电网络发票。使用qr_flutter包可以轻松将该字段转换为二维码。

if(quote.lnInvoice != null) {
  return QrImage(
    data: quote.lnInvoice!,
    version: QrVersions.auto,
    size: 200.0,
  );
}

相关问题

示例代码

import 'package:example/invoices/invoices.dart';
import 'package:example/rates/exchange_rates.dart';
import 'package:example/users/user_search.dart';
import 'package:flutter/material.dart';
import 'package:strike/strike.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';

late final Strike strike;

Future<void> main()  async {
  await dotenv.load(fileName: '.env');

  strike = Strike(
    apiKey: dotenv.env['STRIKE_API_KEY']!,
    debugMode: true,
  );

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Strike API Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Strike API Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  [@override](/user/override)
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  [@override](/user/override)
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: ListView(
        children: [
          ListTile(
            title: const Text('Invoices'),
            onTap: (){
              Navigator.of(context).push(MaterialPageRoute(builder: (context) => const Invoices(),));
            },
          ),
          ListTile(
            onTap: (){
              Navigator.of(context).push(MaterialPageRoute(builder: (context) => UserSearch()));
            },
            title: const Text('User Search'),
          ),
          ListTile(
            onTap: (){
              Navigator.of(context).push(MaterialPageRoute(builder: (context) => ExchangeRates()));
            },
            title: const Text('Exchange Rates'),
          ),
        ],
      ),
    );
  }
}

更多关于Flutter文本装饰插件strike的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html

1 回复

更多关于Flutter文本装饰插件strike的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html


在 Flutter 中,你可以使用 TextStyledecoration 属性来为文本添加装饰效果,例如下划线、删除线等。要实现删除线效果,你可以使用 TextDecoration.lineThrough

以下是一个简单的示例,展示了如何在 Flutter 中使用 TextStyle 来为文本添加删除线:

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Flutter Text Decoration Example'),
        ),
        body: Center(
          child: Text(
            'This text has a strikethrough effect',
            style: TextStyle(
              decoration: TextDecoration.lineThrough,
              fontSize: 24,
            ),
          ),
        ),
      ),
    );
  }
}

解释:

  • TextStyledecoration 属性用于设置文本的装饰效果。
  • TextDecoration.lineThrough 用于在文本中间添加删除线。

其他装饰效果:

  • TextDecoration.underline:添加下划线。
  • TextDecoration.overline:添加上划线。
  • TextDecoration.none:无装饰效果。

你还可以通过 TextDecorationStyle 来设置装饰线的样式,例如虚线或双线:

Text(
  'This text has a dashed strikethrough effect',
  style: TextStyle(
    decoration: TextDecoration.lineThrough,
    decorationStyle: TextDecorationStyle.dashed, // 设置装饰线样式为虚线
    fontSize: 24,
  ),
)
回到顶部
AI 助手
你好,我是IT营的 AI 助手
您可以尝试点击下方的快捷入口开启体验!