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

[Refactor] Remove multiple instances of Flutter toast widgets. #737

Closed
wants to merge 9 commits into from
Closed

Conversation

utkarshshendge
Copy link
Contributor

What kind of change does this PR introduce?
This is a code refactor.
This issue fixes #716 and
Coincidentally fixes #594 .

Did you add tests for your changes?
No, not required

Summary
Instead of creating separate widgets I directly used FlutterToast.showTost(). It gives us the same behavior, prevents text-overflow, and significantly reduces the number of lines in code.

Does this PR introduce a breaking change?
No

@@ -81,7 +78,9 @@ class RegisterFormState extends State<RegisterForm> {
setState(() {
_progressBarState = false;
});
_exceptionToast(result.hasException.toString().substring(16, 35));
Fluttertoast.showToast(
msg: result.hasException.toString().substring(16, 35),
Copy link
Contributor

Choose a reason for hiding this comment

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

What does the absolute values mean? can these be in a constant variable with descriptive names?

Copy link
Contributor

Choose a reason for hiding this comment

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

For example resultsMessageStartPosition and resultsMessageEndPosition

Copy link
Contributor Author

@utkarshshendge utkarshshendge Apr 27, 2021

Choose a reason for hiding this comment

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

What does the absolute values mean? can these be in a constant variable with descriptive names?

@dellyjm by absolute values do you mean the integer values (16 and 35) ?

Copy link
Member

Choose a reason for hiding this comment

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

Already have a separate issue for error handling.

Copy link
Contributor

Choose a reason for hiding this comment

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

What does the absolute values mean? can these be in a constant variable with descriptive names?

@dellyjm by absolute values do you mean the integer values (16 and 35) ?

yes, so name them so that the next developer reviewing understands what the start and end values mean without googling.

Copy link
Contributor Author

@utkarshshendge utkarshshendge Apr 27, 2021

Choose a reason for hiding this comment

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

@dellyjm yes , the next developer may find it difficult to understand.
So the developer who coded this has also added a print statement to print the exception in the console.

Showing the whole exception to the user isn't a good idea.
So result.hasException.toString().substring(16, 35) displays only what the user may understand.
For eg:
This is printed in console (For devs):
ClientException: Failed to connect to http://talawa-graphql-api.herokuapp.com/graphql/talawa/graphql: Failed host lookup: 'talawa-graphql-api.herokuapp.com'

And a substring of that (from index 16 to 35) is for the user:
Failed to connect

These integer values may be different for different exceptions.
There is already a separate issue for error handling refer: issue #673

@@ -68,7 +67,9 @@ class _UrlPageState extends State<UrlPage>
LogHelper().log(LogLevel.ERROR, widget.toStringShort(), "checkAndSetUrl",
"Incorrect Oraganization",
exception: e as Exception);
_exceptionToast('Incorrect Organization Entered');
Fluttertoast.showToast(
msg: 'Incorrect Organization Entered',
Copy link
Contributor

Choose a reason for hiding this comment

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

error messages need to be abstracted out to internationalization file. multiple languages are supported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @dellyjm, as per my knowledge multilingual support is not added yet, it's a part of the GSoC project.
Please see this link : GSoC ideas

Copy link
Contributor

Choose a reason for hiding this comment

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

error messages need to be abstracted out to internationalization file. multiple languages are supported.

@dellyjm We'll open issues on internationalization next week. Like @utkarshshendge said, some GSoC applications may include this feature and it'll be best to wait and see whether any of these are accepted.

@@ -140,7 +132,9 @@ class _AddEventState extends State<AddEvent> {
);
print('Result is : $result');
if (result == null) {
_exceptionToast("Could not create event! Please Try Again later!");
Fluttertoast.showToast(
msg: "Could not create event! Please Try Again later!",
Copy link
Contributor

Choose a reason for hiding this comment

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

no hardcoding of strings. Internationalization file please.

Copy link
Member

Choose a reason for hiding this comment

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

This is going to be already big a seperate issue for that would be much better is guess.

Copy link
Contributor

@dellyjm dellyjm left a comment

Choose a reason for hiding this comment

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

Made some comments in the files.

  1. Magic strings in the code need to be removed
  2. Place Text to be displayed in internationalization file.

} else if (result.hasException) {
print(result.exception);
setState(() {
_progressBarState = false;
});

_exceptionToast(result.exception.toString().substring(16, 35));
Fluttertoast.showToast(
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @utkarshshendge
Can you break the exception here like whether it is GraphqlError or it is ClientException and display message accordingly. It would enhance the experience of user as he/she gets to know whether it is a server side problem or something related to their phone connectivity.

Copy link
Contributor Author

@utkarshshendge utkarshshendge Apr 28, 2021

Choose a reason for hiding this comment

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

@sumitra19jha this is much needed. But it looks a bit out of the scope of this PR.
I think it will be best if a new issue is created for it so we can apply these changes in the entire App.

@dellyjm Should I create a separate issue for this or fix it as a part of this PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

@utkarshshendge if possible add the changes as part of this PR only. Update issue and PR description.
Also fix conflicts on this PR.

lib/views/pages/login_signup/login_form.dart Outdated Show resolved Hide resolved
@utkarshshendge utkarshshendge marked this pull request as draft April 28, 2021 09:46
@utkarshshendge utkarshshendge marked this pull request as ready for review April 28, 2021 13:51
@palisadoes palisadoes requested a review from Sagar2366 April 28, 2021 14:09
@palisadoes
Copy link
Contributor

@utkarshshendge please fix the merge conflicting files

@utkarshshendge utkarshshendge marked this pull request as draft April 28, 2021 19:27
@utkarshshendge
Copy link
Contributor Author

@palisadoes happened a mistake while merging it closing the PR

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.

Migration of all toasts to a common widget [Bug] Toast text RenderFlex overflowed issue
6 participants