|
|
@ -15,8 +15,8 @@ class NotesNotePage extends StatefulWidget { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class _NotesNotePageState extends State<NotesNotePage> { |
|
|
|
class _NotesNotePageState extends State<NotesNotePage> { |
|
|
|
late final _contentController = TextEditingController(); |
|
|
|
late final _contentController = TextEditingController()..text = widget.bloc.initialContent; |
|
|
|
late final _titleController = TextEditingController(); |
|
|
|
late final _titleController = TextEditingController()..text = widget.bloc.initialTitle; |
|
|
|
final _contentFocusNode = FocusNode(); |
|
|
|
final _contentFocusNode = FocusNode(); |
|
|
|
final _titleFocusNode = FocusNode(); |
|
|
|
final _titleFocusNode = FocusNode(); |
|
|
|
bool _showEditor = false; |
|
|
|
bool _showEditor = false; |
|
|
@ -34,41 +34,15 @@ class _NotesNotePageState extends State<NotesNotePage> { |
|
|
|
handleNotesException(context, error); |
|
|
|
handleNotesException(context, error); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
widget.bloc.content.listen((final content) { |
|
|
|
_contentController.addListener(() => widget.bloc.updateContent(_contentController.text)); |
|
|
|
if (_contentController.text != content) { |
|
|
|
_titleController.addListener(() => widget.bloc.updateTitle(_titleController.text)); |
|
|
|
final selection = _contentController.selection; |
|
|
|
|
|
|
|
_contentController |
|
|
|
|
|
|
|
..text = content |
|
|
|
|
|
|
|
..selection = selection; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
widget.bloc.title.listen((final title) { |
|
|
|
|
|
|
|
if (_titleController.text != title) { |
|
|
|
|
|
|
|
final selection = _titleController.selection; |
|
|
|
|
|
|
|
_titleController |
|
|
|
|
|
|
|
..text = title |
|
|
|
|
|
|
|
..selection = selection; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_contentController.addListener(() async { |
|
|
|
|
|
|
|
if (await widget.bloc.content.first != _contentController.text) { |
|
|
|
|
|
|
|
widget.bloc.updateContent(_contentController.text); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
_titleController.addListener(() async { |
|
|
|
|
|
|
|
if (await widget.bloc.title.first != _titleController.text) { |
|
|
|
|
|
|
|
widget.bloc.updateTitle(_titleController.text); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((final _) async { |
|
|
|
WidgetsBinding.instance.addPostFrameCallback((final _) async { |
|
|
|
if (Provider.of<NeonPlatform>(context, listen: false).canUseWakelock) { |
|
|
|
if (Provider.of<NeonPlatform>(context, listen: false).canUseWakelock) { |
|
|
|
await Wakelock.enable(); |
|
|
|
await Wakelock.enable(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (widget.bloc.options.defaultNoteViewTypeOption.value == DefaultNoteViewType.edit || |
|
|
|
if (widget.bloc.options.defaultNoteViewTypeOption.value == DefaultNoteViewType.edit || |
|
|
|
(await widget.bloc.content.first).isEmpty) { |
|
|
|
widget.bloc.initialContent.isEmpty) { |
|
|
|
setState(() { |
|
|
|
setState(() { |
|
|
|
_showEditor = true; |
|
|
|
_showEditor = true; |
|
|
|
}); |
|
|
|
}); |
|
|
@ -171,22 +145,15 @@ class _NotesNotePageState extends State<NotesNotePage> { |
|
|
|
border: InputBorder.none, |
|
|
|
border: InputBorder.none, |
|
|
|
), |
|
|
|
), |
|
|
|
) |
|
|
|
) |
|
|
|
: RxBlocBuilder( |
|
|
|
: MarkdownBody( |
|
|
|
bloc: widget.bloc, |
|
|
|
data: _contentController.text, |
|
|
|
state: (final bloc) => bloc.content, |
|
|
|
onTapLink: (final text, final href, final title) async { |
|
|
|
builder: (final context, final contentSnapshot, final _) { |
|
|
|
if (href != null) { |
|
|
|
final content = contentSnapshot.data ?? ''; |
|
|
|
await launchUrlString( |
|
|
|
return MarkdownBody( |
|
|
|
href, |
|
|
|
data: content, |
|
|
|
mode: LaunchMode.externalApplication, |
|
|
|
onTapLink: (final text, final href, final title) async { |
|
|
|
); |
|
|
|
if (href != null) { |
|
|
|
} |
|
|
|
await launchUrlString( |
|
|
|
|
|
|
|
href, |
|
|
|
|
|
|
|
mode: LaunchMode.externalApplication, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|