Flutter自定义组件插件freewill_fx_widgets的使用
Flutter 自定义组件插件 freewill_fx_widgets 的使用
本插件包包含了一些简单的组件,适用于 FreewillFx 应用程序。
安装
- 在
pubspec.yaml
文件中添加最新版本的插件,并运行flutter pub get
命令。
dependencies:
freewill_fx_widgets: ^1.4.10
- 导入插件并在你的 Flutter 应用程序中使用。
import 'package:freewill_fx_widgets/fx.dart';
TextFontStyle
这是一个可以修改 TextStyle
的文本组件:
- FontFamily
- FontSize
- Color
- TextAlign
- FontWeight
- TextOverflow
- Underline
TextFontStyle(
"Hello World",
fontSize: 20.0,
color: Colors.blue,
textAlign: TextAlign.center,
fontWeight: FontWeight.bold,
maxLines: 1,
overflow: TextOverflow.ellipsis,
decoration: TextDecoration.underline,
)
AlertDialog
这是一个可以修改对话框标题的对话框组件:
- title
- buttonColor
AlertDialog(
title: Text("提示"),
actions: [
TextButton(
onPressed: () {},
child: Text("确定"),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.blue),
),
),
],
)
Loading
这是一个加载页面组件。
PermissionHandler
该组件用于处理权限请求:
- Camera
- Gallery
- Location
// 示例代码省略,具体实现请查阅文档
ImagePicker
该组件用于从相机或图库中选择图片:
- From camera
- From gallery
File? image = await showImagePickerBottomSheet(
color: Colors.black,
cropImage: true,
);
setState(() => _image = image);
PageIndicator
这是页面指示器组件。
GalleryView
这是图库视图组件。
CropImage
在 showImageBottomSheet
中设置 cropImage
为 true
。
File? file = await showImagePickerBottomSheet(
color: Colors.black,
cropImage: true,
);
setState(() => _image = file);
QRCodeScanner
这是一个二维码扫描组件。
Barcode? result = await Get.to(() => FXQrScanner());
if (result != null) {
setState(() => qrResult = result);
}
SubmitButton
这是一个可以修改样式的提交按钮组件:
- Title
- TestKey
- BackgroundColor
- Padding
- BorderWidth
- BorderRadius
- BorderColor
- Shadow
- TextColor
- FontSize
SubmitButton(
title: "提交",
backgroundColor: Colors.blue,
textColor: Colors.white,
padding: EdgeInsets.all(12.0),
borderRadius: BorderRadius.circular(8.0),
borderWidth: 1.0,
borderColor: Colors.black,
shadow: BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 2,
blurRadius: 5,
offset: Offset(0, 3),
),
fontSize: 16.0,
)
OkCancelDialog
这是一个可以自定义标题、图标、内容和按钮的确认对话框组件。
OkCancelDialog(
title: Text("提示"),
content: Text("你确定要执行此操作吗?"),
okButtonText: "确定",
cancelButtonText: "取消",
onOkPressed: () {
// 执行确定操作
},
onCancelPressed: () {
// 执行取消操作
},
)
Switch
这是一个可以添加文本的自定义开关组件。
Switch(
value: _isSwitchOn,
onChanged: (bool value) {
setState(() {
_isSwitchOn = value;
});
},
label: Text("开关"),
)
OTPTextField
这是一个可用于自动化测试的 OTP 文本输入框组件。
OTPTextField(
length: 6,
width: MediaQuery.of(context).size.width,
textFieldAlignment: MainAxisAlignment.spaceAround,
fieldWidth: 40,
style: TextStyle(
fontSize: 17,
),
onChanged: (String pin) {
// 输入改变时的操作
},
)
ToastMessage
这是一个自定义的吐司消息组件(例如复制到剪贴板)。
ToastMessage.show("复制成功", context);
BackButton
这是一个可以自定义图标、阴影并添加圆边的返回按钮组件。
BackButton(
onPressed: () {
Navigator.pop(context);
},
color: Colors.black,
shape: CircleBorder(side: BorderSide(color: Colors.black)),
)
SelectedButton
这是一个可以选择的按钮列表组件(例如在 TERMINUS Mobile 中的过滤组)。
SelectedButton(
options: ["选项1", "选项2", "选项3"],
onSelected: (int index) {
// 选择某个选项时的操作
},
)
ItemPickerPage & ItemPickerCell
这是一个可以选择项目的页面组件,可以自定义选中的标签、选择单元格、单选或多选。
ItemPickerPage(
items: ["选项1", "选项2", "选项3"],
onItemSelected: (int index) {
// 选择某个项目时的操作
},
)
SearchBar
这是一个自定义搜索栏组件。
SearchBar(
hintText: "搜索",
onSubmitted: (String query) {
// 搜索时的操作
},
)
Calendar
这是一个使用 Syncfusion 日期范围选择器构建的日历组件。
// 示例代码省略,具体实现请查阅文档
BottomSheet
这是一个底部弹出框模板组件。
BottomSheet(
onClosing: () {},
builder: (BuildContext context) {
return Container(
height: 200,
child: Center(
child: Text("底部弹出框内容"),
),
);
},
)
NewVersionDialog
这是一个当有新版本时显示的对话框组件。
// 示例代码省略,具体实现请查阅文档
更多关于Flutter自定义组件插件freewill_fx_widgets的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter自定义组件插件freewill_fx_widgets的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
freewill_fx_widgets
是一个 Flutter 自定义组件插件,提供了多种预定义的 UI 组件和功能,帮助开发者快速构建应用界面。以下是该插件的基本使用方法。
1. 安装插件
首先,在 pubspec.yaml
文件中添加 freewill_fx_widgets
依赖:
dependencies:
flutter:
sdk: flutter
freewill_fx_widgets: ^latest_version
然后运行 flutter pub get
来安装插件。
2. 导入插件
在需要使用 freewill_fx_widgets
的 Dart 文件中导入插件:
import 'package:freewill_fx_widgets/freewill_fx_widgets.dart';
3. 使用组件
freewill_fx_widgets
提供了多种预定义的组件,以下是一些常见组件的使用示例。
3.1 按钮组件
FxButton
是一个自定义按钮组件,可以设置多种样式和点击事件。
FxButton(
text: 'Click Me',
onPressed: () {
print('Button Pressed');
},
backgroundColor: Colors.blue,
textColor: Colors.white,
borderRadius: 8.0,
);
3.2 输入框组件
FxTextField
是一个自定义输入框组件,支持多种输入类型和验证功能。
FxTextField(
hintText: 'Enter your name',
onChanged: (value) {
print('Input: $value');
},
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter some text';
}
return null;
},
);
3.3 卡片组件
FxCard
是一个自定义卡片组件,可以设置阴影、边距等样式。
FxCard(
margin: EdgeInsets.all(8.0),
elevation: 4.0,
child: Padding(
padding: EdgeInsets.all(16.0),
child: Text('This is a card'),
),
);
3.4 加载指示器
FxLoadingIndicator
是一个自定义加载指示器组件,支持多种样式和颜色。
FxLoadingIndicator(
size: 40.0,
color: Colors.blue,
);
4. 自定义主题
freewill_fx_widgets
还支持自定义主题,你可以通过 FxTheme
来定义全局的样式。
FxTheme(
primaryColor: Colors.blue,
accentColor: Colors.green,
textTheme: TextTheme(
headline1: TextStyle(fontSize: 32.0, fontWeight: FontWeight.bold),
bodyText1: TextStyle(fontSize: 16.0, color: Colors.black),
),
child: MyApp(),
);
5. 其他功能
freewill_fx_widgets
还提供了其他一些功能,如对话框、SnackBar、Toast 等,你可以根据需要进行使用。
6. 示例代码
以下是一个完整的使用示例:
import 'package:flutter/material.dart';
import 'package:freewill_fx_widgets/freewill_fx_widgets.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
[@override](/user/override)
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Freewill FX Widgets Demo'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
FxButton(
text: 'Click Me',
onPressed: () {
print('Button Pressed');
},
backgroundColor: Colors.blue,
textColor: Colors.white,
borderRadius: 8.0,
),
SizedBox(height: 20),
FxTextField(
hintText: 'Enter your name',
onChanged: (value) {
print('Input: $value');
},
),
SizedBox(height: 20),
FxCard(
margin: EdgeInsets.all(8.0),
elevation: 4.0,
child: Padding(
padding: EdgeInsets.all(16.0),
child: Text('This is a card'),
),
),
SizedBox(height: 20),
FxLoadingIndicator(
size: 40.0,
color: Colors.blue,
),
],
),
),
);
}
}