Skip to content
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

Closed
wants to merge 0 commits into from
Closed

Conversation

Jhalakupadhyay
Copy link
Contributor

#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.

Comment on lines 94 to 122
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,
),
);
Copy link
Collaborator

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();
Copy link
Collaborator

@adityastic adityastic Jun 30, 2024

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 {
Copy link
Collaborator

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

Comment on lines 17 to 25
enum TransferState {
search,
connecting,
connected,
notConnected,
transfer,
permission,
success,
failed,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed

Comment on lines 2 to 5
Future<BleState?> isSuccess(String message);

Future<BleState?> isFailed(String message);

Copy link
Collaborator

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) {
Copy link
Collaborator

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants