error handling with nice snackbar on fabs
This commit is contained in:
parent
eb723b74fd
commit
3d86afa592
1 changed files with 42 additions and 26 deletions
|
@ -160,20 +160,10 @@ class _SftpExplorerState extends State<SftpExplorer> {
|
|||
on SftpStatusError catch (e) {
|
||||
if (context.mounted) {
|
||||
if (e.code == 4) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
behavior: SnackBarBehavior.floating,
|
||||
content: Text('Folder Already Exists')
|
||||
)
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(_buildErrorSnackBar(context, 'Folder Already Exists'));
|
||||
}
|
||||
else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
behavior: SnackBarBehavior.floating,
|
||||
content: Text('Error: ${e.message}')
|
||||
)
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(_buildErrorSnackBar(context, 'Error: ${e.message}'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -194,6 +184,7 @@ class _SftpExplorerState extends State<SftpExplorer> {
|
|||
onPressed: () async {
|
||||
final List<XFile> files = await openFiles();
|
||||
for (XFile file in files) {
|
||||
try {
|
||||
final remoteFile = await widget.sftpClient.open('${widget.path}${file.name}', mode: SftpFileOpenMode.create | SftpFileOpenMode.write | SftpFileOpenMode.exclusive);
|
||||
final fileSize = await file.length();
|
||||
final uploader = remoteFile.write(
|
||||
|
@ -205,9 +196,20 @@ class _SftpExplorerState extends State<SftpExplorer> {
|
|||
_loadingFileName = file.name;
|
||||
});
|
||||
await uploader.done;
|
||||
}
|
||||
setState(() => _loader = null);
|
||||
_listDir();
|
||||
}
|
||||
on SftpStatusError catch (e) {
|
||||
if (context.mounted) {
|
||||
if (e.code == 4) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(_buildErrorSnackBar(context, 'File Already Exists'));
|
||||
}
|
||||
else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(_buildErrorSnackBar(context, 'Error: ${e.message}'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
child: Icon(Icons.upload),
|
||||
),
|
||||
|
@ -215,6 +217,20 @@ class _SftpExplorerState extends State<SftpExplorer> {
|
|||
);
|
||||
}
|
||||
|
||||
SnackBar _buildErrorSnackBar(BuildContext context, String error) {
|
||||
return SnackBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
content: Row(
|
||||
spacing: 10,
|
||||
children: [
|
||||
Icon(Icons.error, color: Colors.red,),
|
||||
Text(error, style: TextStyle(color: Theme.of(context).colorScheme.onSecondaryContainer),),
|
||||
],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLoadingWidget(BuildContext context) {
|
||||
return _loader != null ? Container(
|
||||
color: Theme.of(context).colorScheme.secondaryContainer,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue