Flutter自定义容器插件trendy_container的使用
Flutter自定义容器插件trendy_container的使用
Trendy container 包允许你在你的 Flutter 应用程序中添加一个漂亮的渐变容器。就像即插即用一样。
安装
- 将最新版本的包添加到你的
pubspec.yaml
文件(然后运行dart pub get
):
dependencies:
trendy_container: ^0.0.1
- 导入包并在你的 Flutter 应用程序中使用它:
import 'package:trendy_container/trendy_container.dart';
示例
你可以修改许多属性:
height
width
title
subtitle
gradient
(颜色1和颜色2)centerTitle
titleTextStyle
subtitleTextStyle
padding
isCircle
isRectangle
示例代码
以下是一个完整的示例代码,展示了如何在 Flutter 应用程序中使用 TrendyContainer
插件:
import 'package:flutter/material.dart';
import 'package:trendy_container/trendy_container.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
[@override](/user/override)
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
[@override](/user/override)
Widget build(BuildContext context) {
return const Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// 第一个渐变矩形容器
TrendyContainer(
title: '这是标题',
subTitle: '这是副标题',
titleTextStyle: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
subtitleTextStyle: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
isRectangle: true,
padding: EdgeInsets.all(10),
height: 150,
width: 300,
centerTitle: true,
color1: Colors.red,
color2: Colors.orange,
),
SizedBox(
height: 50,
),
// 第二个渐变矩形容器
TrendyContainer(
title: '这是标题',
subTitle: '这是副标题',
titleTextStyle: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
subtitleTextStyle: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
padding: EdgeInsets.all(10),
height: 150,
width: 300,
centerTitle: true,
color1: Colors.green,
color2: Colors.greenAccent,
),
SizedBox(
height: 50,
),
// 圆形渐变容器
TrendyContainer(
title: '这是标题',
subTitle: '这是副标题',
titleTextStyle: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
subtitleTextStyle: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
padding: EdgeInsets.all(10),
height: 180,
width: 300,
isCircle: true,
centerTitle: true,
color1: Colors.blueAccent,
color2: Colors.lightBlue,
),
],
),
),
);
}
}
更多关于Flutter自定义容器插件trendy_container的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter自定义容器插件trendy_container的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
TrendyContainer
是一个自定义的 Flutter 容器插件,通常用于创建具有现代、时尚设计风格的容器。它可能包含一些内置的样式、阴影、圆角、渐变背景等效果,帮助你快速构建美观的 UI 组件。
以下是如何使用 TrendyContainer
插件的基本步骤:
1. 添加依赖
首先,你需要在 pubspec.yaml
文件中添加 trendy_container
插件的依赖。
dependencies:
flutter:
sdk: flutter
trendy_container: ^1.0.0 # 请替换为最新版本
然后运行 flutter pub get
来安装依赖。
2. 导入包
在你的 Dart 文件中导入 trendy_container
包。
import 'package:trendy_container/trendy_container.dart';
3. 使用 TrendyContainer
你可以像使用普通的 Container
一样使用 TrendyContainer
,但它提供了更多的内置样式和属性。
TrendyContainer(
width: 200,
height: 200,
borderRadius: BorderRadius.circular(20),
gradient: LinearGradient(
colors: [Colors.blue, Colors.purple],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
shadow: BoxShadow(
color: Colors.black.withOpacity(0.3),
blurRadius: 10,
spreadRadius: 5,
),
child: Center(
child: Text(
'Trendy Container',
style: TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
);
4. 自定义属性
TrendyContainer
可能支持以下常见属性:
width
和height
: 容器的宽度和高度。borderRadius
: 圆角半径。gradient
: 渐变背景。shadow
: 阴影效果。color
: 背景颜色(如果不需要渐变)。child
: 容器的子组件。
5. 其他功能
根据插件的具体实现,TrendyContainer
可能还支持其他功能,比如动画、边框、内边距等。你可以查看插件的文档或源代码来了解更多细节。
6. 示例
以下是一个完整的示例,展示了如何使用 TrendyContainer
创建一个具有渐变背景和阴影效果的容器。
import 'package:flutter/material.dart';
import 'package:trendy_container/trendy_container.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Trendy Container Example'),
),
body: Center(
child: TrendyContainer(
width: 200,
height: 200,
borderRadius: BorderRadius.circular(20),
gradient: LinearGradient(
colors: [Colors.blue, Colors.purple],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
shadow: BoxShadow(
color: Colors.black.withOpacity(0.3),
blurRadius: 10,
spreadRadius: 5,
),
child: Center(
child: Text(
'Trendy Container',
style: TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
),
),
),
);
}
}