mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-27 01:02:14 +08:00
Use Flushbar for Snackbars
The flutter default Snackbars are a major PITA to use as they require a Scaffold, additionaly, they will not be shown if the parent Scaffold is destroyed, which is the case when deleting a note and returning to the main screen.
This commit is contained in:
@ -9,6 +9,7 @@ import 'package:gitjournal/analytics.dart';
|
||||
import 'package:gitjournal/apis/git.dart';
|
||||
import 'package:gitjournal/apis/githost_factory.dart';
|
||||
import 'package:gitjournal/state_container.dart';
|
||||
import 'package:gitjournal/utils.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
@ -319,10 +320,7 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
||||
|
||||
void _copyKeyToClipboard(BuildContext context) {
|
||||
Clipboard.setData(ClipboardData(text: publicKey));
|
||||
var text = "Public Key copied to Clipboard";
|
||||
Scaffold.of(context)
|
||||
..removeCurrentSnackBar()
|
||||
..showSnackBar(SnackBar(content: Text(text)));
|
||||
showSnackbar(context, "Public Key copied to Clipboard");
|
||||
}
|
||||
|
||||
void _launchDeployKeyPage() async {
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'package:badges/badges.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gitjournal/note.dart';
|
||||
import 'package:gitjournal/utils.dart';
|
||||
import 'package:gitjournal/apis/git.dart';
|
||||
import 'package:gitjournal/screens/note_editor.dart';
|
||||
import 'package:gitjournal/screens/note_viewer.dart';
|
||||
@ -72,9 +73,7 @@ class HomeScreen extends StatelessWidget {
|
||||
try {
|
||||
await container.syncNotes();
|
||||
} on GitException catch (exp) {
|
||||
_scaffoldKey.currentState
|
||||
..removeCurrentSnackBar()
|
||||
..showSnackBar(SnackBar(content: Text(exp.cause)));
|
||||
showSnackbar(context, exp.cause);
|
||||
}
|
||||
}),
|
||||
),
|
||||
|
@ -28,7 +28,6 @@ class NoteBrowsingScreen extends StatefulWidget {
|
||||
|
||||
class NoteBrowsingScreenState extends State<NoteBrowsingScreen> {
|
||||
PageController pageController;
|
||||
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
NoteBrowsingScreenState({@required int noteIndex}) {
|
||||
pageController = PageController(initialPage: noteIndex);
|
||||
@ -49,7 +48,6 @@ class NoteBrowsingScreenState extends State<NoteBrowsingScreen> {
|
||||
);
|
||||
|
||||
return Scaffold(
|
||||
key: _scaffoldKey,
|
||||
appBar: AppBar(
|
||||
title: Text('TIMELINE'),
|
||||
actions: <Widget>[
|
||||
@ -97,10 +95,7 @@ class NoteBrowsingScreenState extends State<NoteBrowsingScreen> {
|
||||
Navigator.pop(context);
|
||||
|
||||
Fimber.d("Shwoing an undo snackbar");
|
||||
var snackbar = buildUndoDeleteSnackbar(context, note, noteIndex);
|
||||
_scaffoldKey.currentState
|
||||
..removeCurrentSnackBar()
|
||||
..showSnackBar(snackbar);
|
||||
showUndoDeleteSnackbar(context, note, noteIndex);
|
||||
}
|
||||
|
||||
Widget _buildAlertDialog(BuildContext context) {
|
||||
|
@ -3,6 +3,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:package_info/package_info.dart';
|
||||
|
||||
import 'package:flushbar/flushbar.dart';
|
||||
|
||||
import 'app.dart';
|
||||
import 'note.dart';
|
||||
import 'state_container.dart';
|
||||
@ -40,22 +42,33 @@ Future<String> dumpAppLogs() async {
|
||||
return logsFilePath;
|
||||
}
|
||||
|
||||
SnackBar buildUndoDeleteSnackbar(
|
||||
void showUndoDeleteSnackbar(
|
||||
BuildContext context,
|
||||
Note deletedNote,
|
||||
int deletedNoteIndex,
|
||||
) {
|
||||
var snackbar = SnackBar(
|
||||
content: Text("Note Deleted"),
|
||||
action: SnackBarAction(
|
||||
label: "Undo",
|
||||
var theme = Theme.of(context);
|
||||
|
||||
Flushbar(
|
||||
message: "Note Deleted",
|
||||
duration: Duration(seconds: 3),
|
||||
mainButton: FlatButton(
|
||||
child: Text(
|
||||
"Undo",
|
||||
style: TextStyle(color: theme.accentColor),
|
||||
),
|
||||
onPressed: () {
|
||||
Fimber.d("Undoing delete");
|
||||
var stateContainer = StateContainer.of(context);
|
||||
stateContainer.undoRemoveNote(deletedNote, deletedNoteIndex);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
return snackbar;
|
||||
).show(context);
|
||||
}
|
||||
|
||||
void showSnackbar(BuildContext context, String message) {
|
||||
Flushbar(
|
||||
message: message,
|
||||
duration: Duration(seconds: 3),
|
||||
).show(context);
|
||||
}
|
||||
|
@ -58,8 +58,7 @@ class JournalList extends StatelessWidget {
|
||||
final stateContainer = StateContainer.of(context);
|
||||
stateContainer.removeNote(note);
|
||||
|
||||
Scaffold.of(context)
|
||||
.showSnackBar(buildUndoDeleteSnackbar(context, note, i));
|
||||
showUndoDeleteSnackbar(context, note, i);
|
||||
},
|
||||
);
|
||||
},
|
||||
|
@ -127,6 +127,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.0.2"
|
||||
flushbar:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flushbar
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.9.0"
|
||||
flutter:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: gitjournal
|
||||
description: A Journaling App Built on top of Git
|
||||
version: 1.1.15+10
|
||||
version: 1.1.16+10
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
@ -26,6 +26,7 @@ dependencies:
|
||||
auto_size_text: ^2.0.1
|
||||
fimber: ^0.3.0
|
||||
dynamic_theme: ^1.0.0
|
||||
flushbar: ^1.9.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_launcher_icons: "^0.7.2"
|
||||
|
Reference in New Issue
Block a user