-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Added the BLE state machine to handle each transfer state gracefully. #960
Conversation
ScaffoldMessenger.of(cardData.getContext()!).showSnackBar( | ||
SnackBar( | ||
margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 10), | ||
elevation: 10, | ||
duration: const Duration(seconds: 1), | ||
content: const Row( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
Image( | ||
image: AssetImage('assets/icons/icon.png'), | ||
height: 20, | ||
), | ||
SizedBox( | ||
width: 10, | ||
), | ||
Text( | ||
'Searching for device...', | ||
style: TextStyle(color: Colors.black), | ||
) | ||
], | ||
), | ||
backgroundColor: Colors.white, | ||
behavior: SnackBarBehavior.floating, | ||
shape: RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(10), | ||
), | ||
dismissDirection: DismissDirection.startToEnd, | ||
), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be part of Scanning state
@override | ||
Future<BleState?> isSuccess(String message) async { | ||
toast.successToast(message); | ||
return ConnectState(scanResult: foundDevice!).processState(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can have a cleaner implementation by sending the state back to the main thread and let it execute until completion instead of having a nested call
} | ||
|
||
@override | ||
Future<BleState?> processState() async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're not making use of the returned BLEState. Every state returns null. I'd advise cleaning this up and returning the next state rather than making nested calls. Letting the main thread run until completion
lib/constants.dart
Outdated
enum TransferState { | ||
search, | ||
connecting, | ||
connected, | ||
notConnected, | ||
transfer, | ||
permission, | ||
success, | ||
failed, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be removed
Future<BleState?> isSuccess(String message); | ||
|
||
Future<BleState?> isFailed(String message); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These method can be improvised or removed. Showing Success or Failed Toast can be a Completed State. That state shows a toast
} | ||
|
||
//show toast for failure state of BLE | ||
void failureToast(String message) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a duplicate of the above. Why not reuse the function?
#959 Before the whole logic for transfer of data was in one file now the logic is divided into different states and each state is handled an according to the success and failure of the state toast is shown on the device.