mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 09:47:35 +08:00
Editors: Remove code duplication
This commit is contained in:
@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:gitjournal/core/note.dart';
|
||||
import 'package:gitjournal/editors/common.dart';
|
||||
import 'package:gitjournal/editors/disposable_change_notifier.dart';
|
||||
import 'package:gitjournal/editors/note_body_editor.dart';
|
||||
import 'package:gitjournal/widgets/editor_scroll_view.dart';
|
||||
import 'package:gitjournal/widgets/journal_editor_header.dart';
|
||||
|
||||
@ -89,7 +90,7 @@ class JournalEditorState extends State<JournalEditor>
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
JournalEditorHeader(note),
|
||||
_NoteBodyEditor(
|
||||
NoteBodyEditor(
|
||||
textController: _textController,
|
||||
autofocus: widget.isNewNote,
|
||||
onChanged: _noteTextChanged,
|
||||
@ -142,32 +143,3 @@ class JournalEditorState extends State<JournalEditor>
|
||||
@override
|
||||
bool get noteModified => _noteModified;
|
||||
}
|
||||
|
||||
class _NoteBodyEditor extends StatelessWidget {
|
||||
final TextEditingController textController;
|
||||
final bool autofocus;
|
||||
final Function onChanged;
|
||||
|
||||
_NoteBodyEditor({this.textController, this.autofocus, this.onChanged});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var style = Theme.of(context).textTheme.subtitle1;
|
||||
|
||||
return TextField(
|
||||
autofocus: autofocus,
|
||||
keyboardType: TextInputType.multiline,
|
||||
maxLines: null,
|
||||
style: style,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Write here',
|
||||
border: InputBorder.none,
|
||||
isDense: true,
|
||||
),
|
||||
controller: textController,
|
||||
textCapitalization: TextCapitalization.sentences,
|
||||
scrollPadding: const EdgeInsets.all(0.0),
|
||||
onChanged: (_) => onChanged(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import 'package:gitjournal/core/note.dart';
|
||||
import 'package:gitjournal/editors/common.dart';
|
||||
import 'package:gitjournal/editors/disposable_change_notifier.dart';
|
||||
import 'package:gitjournal/editors/heuristics.dart';
|
||||
import 'package:gitjournal/editors/note_body_editor.dart';
|
||||
import 'package:gitjournal/editors/note_title_editor.dart';
|
||||
import 'package:gitjournal/error_reporting.dart';
|
||||
import 'package:gitjournal/settings.dart';
|
||||
@ -118,7 +119,7 @@ class MarkdownEditorState extends State<MarkdownEditor>
|
||||
_titleTextController,
|
||||
_noteTextChanged,
|
||||
),
|
||||
_NoteBodyEditor(
|
||||
NoteBodyEditor(
|
||||
textController: _textController,
|
||||
autofocus: widget.isNewNote,
|
||||
onChanged: _noteTextChanged,
|
||||
@ -227,36 +228,3 @@ class MarkdownEditorState extends State<MarkdownEditor>
|
||||
@override
|
||||
bool get noteModified => _noteModified;
|
||||
}
|
||||
|
||||
class _NoteBodyEditor extends StatelessWidget {
|
||||
final TextEditingController textController;
|
||||
final bool autofocus;
|
||||
final Function onChanged;
|
||||
|
||||
_NoteBodyEditor({
|
||||
@required this.textController,
|
||||
@required this.autofocus,
|
||||
@required this.onChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var style = Theme.of(context).textTheme.subtitle1;
|
||||
|
||||
return TextField(
|
||||
autofocus: autofocus,
|
||||
keyboardType: TextInputType.multiline,
|
||||
maxLines: null,
|
||||
style: style,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Write here',
|
||||
border: InputBorder.none,
|
||||
isDense: true,
|
||||
),
|
||||
controller: textController,
|
||||
textCapitalization: TextCapitalization.sentences,
|
||||
scrollPadding: const EdgeInsets.all(0.0),
|
||||
onChanged: (_) => onChanged(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
30
lib/editors/note_body_editor.dart
Normal file
30
lib/editors/note_body_editor.dart
Normal file
@ -0,0 +1,30 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class NoteBodyEditor extends StatelessWidget {
|
||||
final TextEditingController textController;
|
||||
final bool autofocus;
|
||||
final Function onChanged;
|
||||
|
||||
NoteBodyEditor({this.textController, this.autofocus, this.onChanged});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var style = Theme.of(context).textTheme.subtitle1;
|
||||
|
||||
return TextField(
|
||||
autofocus: autofocus,
|
||||
keyboardType: TextInputType.multiline,
|
||||
maxLines: null,
|
||||
style: style,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Write here',
|
||||
border: InputBorder.none,
|
||||
isDense: true,
|
||||
),
|
||||
controller: textController,
|
||||
textCapitalization: TextCapitalization.sentences,
|
||||
scrollPadding: const EdgeInsets.all(0.0),
|
||||
onChanged: (_) => onChanged(),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user