如何使用GetX弹奏自定义按钮加载?
我想自定义一个按钮,该按钮在使用GETX从API获取数据时显示了加载动作,我可以通过任何控制器。
注意:每个控制器都有字段 isloading
示例:
- usercontroller
- dectionsController
- objecterController,
class BtnAction<T> extends GetView<ConnectivityController> {
final String text;
final GestureTapCallback press;
final Color color;
final Color textColor;
final T isLoading;
const BtnAction(
{Key? key,
required this.text,
required this.press,
required this.color,
required this.isLoading,
required this.textColor})
: super(key: key);
@override
Widget build(BuildContext context) {
return Obx(() {
if (controller.connectionStatus.value.name == 'none') {
return TextButton.icon(
onPressed: null,
style: TextButton.styleFrom(backgroundColor: Colors.blueGrey),
label: Text(text, style: TextStyle(color: textColor)),
icon: Icon(Icons.wifi_off_sharp, color: textColor));
} else {
if (isLoading as (T).isLoading) {
return TextButton(
onPressed: press,
style: TextButton.styleFrom(
splashFactory: NoSplash.splashFactory,
backgroundColor: color,
primary: textColor,
padding: EdgeInsets.zero,
),
child: Text(text),
);
} else {
return TextButton(
onPressed: press,
style: TextButton.styleFrom(
splashFactory: NoSplash.splashFactory,
backgroundColor: color,
primary: textColor,
padding: EdgeInsets.zero,
),
child: Text(text),
);
}
}
});
}
}
//on click
SizedBox(
width: double.infinity,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 15),
child: BtnAction<UserController>(
text: "Filter",
textColor: Colors.white,
color: Colors.black,
isLoading: controller,
press: () async {
controller.fetchUser(UserRequest());
},
),
),
),
请给我一些建议,以了解我该如何实现这一目标。
谢谢你!!
I would like to customize a button that showed loading action while fetching data from API using GetX which I can pass any controllers.
Note: Each controller has field isLoading
Example:
- UserController
- DepartmentController
- SubjectController
class BtnAction<T> extends GetView<ConnectivityController> {
final String text;
final GestureTapCallback press;
final Color color;
final Color textColor;
final T isLoading;
const BtnAction(
{Key? key,
required this.text,
required this.press,
required this.color,
required this.isLoading,
required this.textColor})
: super(key: key);
@override
Widget build(BuildContext context) {
return Obx(() {
if (controller.connectionStatus.value.name == 'none') {
return TextButton.icon(
onPressed: null,
style: TextButton.styleFrom(backgroundColor: Colors.blueGrey),
label: Text(text, style: TextStyle(color: textColor)),
icon: Icon(Icons.wifi_off_sharp, color: textColor));
} else {
if (isLoading as (T).isLoading) {
return TextButton(
onPressed: press,
style: TextButton.styleFrom(
splashFactory: NoSplash.splashFactory,
backgroundColor: color,
primary: textColor,
padding: EdgeInsets.zero,
),
child: Text(text),
);
} else {
return TextButton(
onPressed: press,
style: TextButton.styleFrom(
splashFactory: NoSplash.splashFactory,
backgroundColor: color,
primary: textColor,
padding: EdgeInsets.zero,
),
child: Text(text),
);
}
}
});
}
}
//on click
SizedBox(
width: double.infinity,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 15),
child: BtnAction<UserController>(
text: "Filter",
textColor: Colors.white,
color: Colors.black,
isLoading: controller,
press: () async {
controller.fetchUser(UserRequest());
},
),
),
),
Please kindly give me some advice on how can I achieve this.
Thank you!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论