move NoteEditorSelector to its own file

This commit is contained in:
Vishesh Handa
2020-03-30 13:09:19 +02:00
parent a5fcb19d70
commit 564fa4cbc0
2 changed files with 51 additions and 36 deletions

View File

@ -10,6 +10,7 @@ import 'package:gitjournal/editors/checklist_editor.dart';
import 'package:gitjournal/settings.dart'; import 'package:gitjournal/settings.dart';
import 'package:gitjournal/state_container.dart'; import 'package:gitjournal/state_container.dart';
import 'package:gitjournal/widgets/folder_selection_dialog.dart'; import 'package:gitjournal/widgets/folder_selection_dialog.dart';
import 'package:gitjournal/widgets/note_editor_selector.dart';
import 'package:gitjournal/widgets/rename_dialog.dart'; import 'package:gitjournal/widgets/rename_dialog.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@ -145,45 +146,10 @@ class NoteEditorState extends State<NoteEditor> {
} }
void _noteEditorChooserSelected(Note _note) async { void _noteEditorChooserSelected(Note _note) async {
var onEditorChange = (EditorType et) => Navigator.of(context).pop(et);
var newEditorType = await showDialog<EditorType>( var newEditorType = await showDialog<EditorType>(
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
var children = <Widget>[ return NoteEditorSelector(editorType);
RadioListTile<EditorType>(
title: const Text("Markdown Editor"),
value: EditorType.Markdown,
groupValue: editorType,
onChanged: onEditorChange,
),
RadioListTile<EditorType>(
title: const Text("Raw Editor"),
value: EditorType.Raw,
groupValue: editorType,
onChanged: onEditorChange,
),
RadioListTile<EditorType>(
title: const Text("Checklist Editor"),
value: EditorType.Checklist,
groupValue: editorType,
onChanged: onEditorChange,
),
RadioListTile<EditorType>(
title: const Text("Journal Editor"),
value: EditorType.Journal,
groupValue: editorType,
onChanged: onEditorChange,
),
];
return AlertDialog(
title: const Text("Choose Editor"),
content: Column(
children: children,
mainAxisSize: MainAxisSize.min,
),
);
}, },
); );

View File

@ -0,0 +1,49 @@
import 'package:flutter/material.dart';
import 'package:gitjournal/screens/note_editor.dart';
class NoteEditorSelector extends StatelessWidget {
final EditorType currentEditor;
NoteEditorSelector(this.currentEditor);
@override
Widget build(BuildContext context) {
var onEditorChange = (EditorType et) => Navigator.of(context).pop(et);
var children = <Widget>[
// FIXME: Change this to ListTiles with nice icons
RadioListTile<EditorType>(
title: const Text("Markdown Editor"),
value: EditorType.Markdown,
groupValue: currentEditor,
onChanged: onEditorChange,
),
RadioListTile<EditorType>(
title: const Text("Raw Editor"),
value: EditorType.Raw,
groupValue: currentEditor,
onChanged: onEditorChange,
),
RadioListTile<EditorType>(
title: const Text("Checklist Editor"),
value: EditorType.Checklist,
groupValue: currentEditor,
onChanged: onEditorChange,
),
RadioListTile<EditorType>(
title: const Text("Journal Editor"),
value: EditorType.Journal,
groupValue: currentEditor,
onChanged: onEditorChange,
),
];
return AlertDialog(
title: const Text("Choose Editor"),
content: Column(
children: children,
mainAxisSize: MainAxisSize.min,
),
);
}
}