Flutter标签胶囊组件插件tag_capsule的使用
Flutter标签胶囊组件插件tag_capsule
的使用
在Flutter开发中,有时我们需要一个简单且美观的标签胶囊组件来展示分类、标签或其他信息。本文将介绍如何使用tag_capsule
插件来快速实现这一功能。
安装插件
首先,在pubspec.yaml
文件中添加tag_capsule
依赖:
dependencies:
tag_capsule: ^1.0.0
然后运行以下命令以安装依赖:
flutter pub get
使用示例
以下是一个完整的示例代码,展示如何使用tag_capsule
插件创建一个带有不同样式的标签胶囊组件。
import 'package:flutter/material.dart';
import 'package:tag_capsule/tag_capsule.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Tag Capsule 示例'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// 创建一个基本的标签胶囊
TagCapsule(
label: '热门',
color: Colors.blue,
textColor: Colors.white,
borderRadius: 8.0,
),
SizedBox(height: 16.0), // 添加间距
// 创建一个带边框的标签胶囊
TagCapsule(
label: '推荐',
color: Colors.transparent,
borderColor: Colors.green,
textColor: Colors.green,
borderWidth: 2.0,
borderRadius: 10.0,
),
SizedBox(height: 16.0),
// 创建一个带阴影的标签胶囊
TagCapsule(
label: '折扣',
color: Colors.orange,
shadowColor: Colors.orange.shade300,
textColor: Colors.white,
borderRadius: 12.0,
elevation: 4.0,
),
],
),
),
),
);
}
}
1 回复