Skip to content

Commit

Permalink
Fix back from editor
Browse files Browse the repository at this point in the history
  • Loading branch information
maelchiotti committed Feb 14, 2024
1 parent 2d445a5 commit cfdf095
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
15 changes: 7 additions & 8 deletions lib/common/actions/add.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:localmaterialnotes/common/routing/router.dart';
import 'package:localmaterialnotes/common/routing/editor_parameters.dart';
import 'package:localmaterialnotes/common/routing/router_route.dart';
import 'package:localmaterialnotes/models/note/note.dart';
import 'package:localmaterialnotes/providers/current_note/current_note_provider.dart';
Expand All @@ -14,12 +14,11 @@ Future<void> addNote(BuildContext context, WidgetRef ref, {String? content}) asy
await ref.read(notesProvider.notifier).add(note);

if (context.mounted) {
context.push(
RouterRoute.editor.fullPath!,
extra: EditorParameters.from({
'readonly': false,
'autofocus': true,
}),
);
final route = RouterRoute.editor.fullPath!;

// If the editor is already opened with another note, replace the route with the new editor
RouterRoute.isEditor
? context.pushReplacement(route, extra: editorParametersNewNote)
: context.push(route, extra: editorParametersNewNote);
}
}
6 changes: 6 additions & 0 deletions lib/common/routing/editor_parameters.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
typedef EditorParameters = Map<String, bool>?;

final editorParametersNewNote = EditorParameters.from({
'readonly': false,
'autofocus': true,
});
2 changes: 1 addition & 1 deletion lib/common/routing/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'package:localmaterialnotes/pages/notes/notes_page.dart';
import 'package:localmaterialnotes/pages/settings/settings_page.dart';
import 'package:localmaterialnotes/utils/constants/constants.dart';

typedef EditorParameters = Map<String, bool>?;
import 'editor_parameters.dart';

CustomTransitionPage _getCustomTransitionPage<T>(GoRouterState state, Widget child) {
return CustomTransitionPage<T>(
Expand Down
2 changes: 2 additions & 0 deletions lib/common/routing/router_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ enum RouterRoute {
}

static bool get isBin => RouterRoute.currentRoute == RouterRoute.bin;

static bool get isEditor => RouterRoute.currentRoute == RouterRoute.editor;
}
3 changes: 2 additions & 1 deletion lib/common/widgets/note_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:go_router/go_router.dart';
import 'package:localmaterialnotes/common/actions/delete.dart';
import 'package:localmaterialnotes/common/actions/pin.dart';
import 'package:localmaterialnotes/common/actions/restore.dart';
import 'package:localmaterialnotes/common/routing/router.dart';
import 'package:localmaterialnotes/common/routing/router_route.dart';
import 'package:localmaterialnotes/models/note/note.dart';
import 'package:localmaterialnotes/providers/bin/bin_provider.dart';
Expand All @@ -15,6 +14,8 @@ import 'package:localmaterialnotes/utils/constants/constants.dart';
import 'package:localmaterialnotes/utils/constants/paddings.dart';
import 'package:localmaterialnotes/utils/constants/sizes.dart';

import '../routing/editor_parameters.dart';

class NoteTile extends ConsumerStatefulWidget {
const NoteTile(this.note) : searchView = false;

Expand Down

0 comments on commit cfdf095

Please sign in to comment.