Skip to content

Commit

Permalink
fix toast on mobile devices
Browse files Browse the repository at this point in the history
  • Loading branch information
LiquidatorCoder committed Nov 27, 2021
1 parent 3f4c687 commit b5b8893
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
4 changes: 3 additions & 1 deletion lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,9 @@ class _HomePageState extends State<HomePage>
Platform.isIOS || Platform.isMacOS
? CupertinoIcons.check_mark
: Icons.check,
"Token copied to clipboard.")),
Platform.isIOS || Platform.isAndroid
? "Link copied to clipboard."
: "Token copied to clipboard.")),
child: Container(
decoration: BoxDecoration(
color: Colors.white12,
Expand Down
35 changes: 23 additions & 12 deletions lib/services/toast_service.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:google_fonts/google_fonts.dart';
Expand Down Expand Up @@ -43,18 +45,27 @@ class ToastService {
),
));
fToast.removeCustomToast();

fToast.showToast(
child: toast,
positionedToastBuilder: (context, child) {
return Positioned(
child: child,
top: 32.0 + MediaQuery.of(context).padding.top,
left: MediaQuery.of(context).size.width / 2 - 125,
);
},
toastDuration: const Duration(seconds: 2),
);
if (Platform.isIOS || Platform.isAndroid) {
Fluttertoast.showToast(
msg: text,
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
textColor: Colors.white,
fontSize: 16.0);
} else {
fToast.showToast(
child: toast,
positionedToastBuilder: (context, child) {
return Positioned(
child: child,
top: 32.0 + MediaQuery.of(context).padding.top,
left: MediaQuery.of(context).size.width / 2 - 125,
);
},
toastDuration: const Duration(seconds: 2),
);
}
}

void showMobileToast(String text) {
Expand Down

0 comments on commit b5b8893

Please sign in to comment.