make error snack bar fn global
This commit is contained in:
parent
045d0694e7
commit
a45378a094
3 changed files with 22 additions and 17 deletions
|
@ -28,3 +28,17 @@ class MainApp extends StatelessWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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),),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import 'package:dartssh2/dartssh2.dart';
|
||||||
import 'package:file_picker/file_picker.dart';
|
import 'package:file_picker/file_picker.dart';
|
||||||
import 'package:file_selector/file_selector.dart';
|
import 'package:file_selector/file_selector.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:fluxcloud/main.dart';
|
||||||
import 'package:fluxcloud/sftp_worker.dart';
|
import 'package:fluxcloud/sftp_worker.dart';
|
||||||
|
|
||||||
import 'widgets/operation_buttons.dart';
|
import 'widgets/operation_buttons.dart';
|
||||||
|
@ -39,7 +40,7 @@ class _SftpExplorerState extends State<SftpExplorer> {
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(_buildErrorSnackBar(context, e.toString()));
|
ScaffoldMessenger.of(context).showSnackBar(buildErrorSnackBar(context, e.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setState(() => _isLoading = false);
|
setState(() => _isLoading = false);
|
||||||
|
@ -168,7 +169,7 @@ class _SftpExplorerState extends State<SftpExplorer> {
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(_buildErrorSnackBar(context, e.toString()));
|
ScaffoldMessenger.of(context).showSnackBar(buildErrorSnackBar(context, e.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
|
@ -202,7 +203,7 @@ class _SftpExplorerState extends State<SftpExplorer> {
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(_buildErrorSnackBar(context, e.toString()));
|
ScaffoldMessenger.of(context).showSnackBar(buildErrorSnackBar(context, e.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setState(() => _progress = null);
|
setState(() => _progress = null);
|
||||||
|
@ -214,17 +215,4 @@ 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),),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:dartssh2/dartssh2.dart';
|
import 'package:dartssh2/dartssh2.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:fluxcloud/main.dart';
|
||||||
import 'package:fluxcloud/sftp_worker.dart';
|
import 'package:fluxcloud/sftp_worker.dart';
|
||||||
|
|
||||||
class OperationButtons extends StatelessWidget {
|
class OperationButtons extends StatelessWidget {
|
||||||
|
@ -97,7 +98,9 @@ class OperationButtons extends StatelessWidget {
|
||||||
await sftpWorker.remove(dirEntry, path);
|
await sftpWorker.remove(dirEntry, path);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
print(e.toString());
|
if (context.mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(buildErrorSnackBar(context, e.toString()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
listDir();
|
listDir();
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue