Last active
December 29, 2020 12:03
-
-
Save IsmailAlamKhan/73621a3bd187f56a0fb5ae6007f160e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:get/get.dart'; | |
class Controller extends GetxController with StateMixin<String> { | |
final String changeThis = 'Super Cool String'; | |
@override | |
Future<void> onInit() async { | |
await Future.delayed(2.seconds); //To see the loading | |
change(changeThis, status: RxStatus.success()); | |
await Future.delayed(10.seconds); //To wait before showing empty | |
change(changeThis, status: RxStatus.loading()); | |
await Future.delayed(5.seconds); //To see the loading | |
change( | |
null, | |
status: RxStatus.empty(), | |
); //To Show Empty | |
await Future.delayed(10.seconds); //To wait before showing error | |
change(changeThis, status: RxStatus.loading()); | |
await Future.delayed(5.seconds); //To see the loading | |
change( | |
changeThis, | |
status: RxStatus.error('Sorry I don\'t know what the error is'), | |
); //To Show Error | |
super.onInit(); | |
} | |
} | |
class View extends GetView<Controller> { | |
const View({Key key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return controller.obx( | |
(state) => ListTile( | |
title: Text(state), | |
), | |
onEmpty: ListTile( | |
//For Custom Empty Widget | |
title: Text('I am totally empty'), | |
), | |
onError: (error) => ListTile( | |
//For Custom Error Messege | |
title: Text(error), | |
), | |
onLoading: ListTile( | |
//For Custom Loading | |
title: Align( | |
alignment: Alignment.centerLeft, | |
child: CircularProgressIndicator(), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment