1
0
mirror of https://github.com/krawieck/lemmur/ synced 2024-12-13 00:56:13 +01:00
lemmur-app-android/lib/widgets/editor.dart
2021-04-27 22:22:02 +02:00

61 lines
1.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'markdown_text.dart';
/// A text field with added functionality for ease of editing
class Editor extends HookWidget {
final TextEditingController? controller;
final FocusNode? focusNode;
final ValueChanged<String>? onSubmitted;
final int? minLines;
final int? maxLines;
final String? labelText;
final bool autofocus;
/// Whether the editor should be preview the contents
final bool fancy;
final String instanceHost;
const Editor({
Key? key,
this.controller,
this.focusNode,
this.onSubmitted,
this.minLines = 5,
this.maxLines,
this.labelText,
this.fancy = false,
required this.instanceHost,
this.autofocus = false,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final defaultController = useTextEditingController();
final actualController = controller ?? defaultController;
if (fancy) {
return Padding(
padding: const EdgeInsets.all(8),
child: MarkdownText(
actualController.text,
instanceHost: instanceHost,
),
);
}
return TextField(
controller: actualController,
focusNode: focusNode,
autofocus: autofocus,
keyboardType: TextInputType.multiline,
textCapitalization: TextCapitalization.sentences,
onSubmitted: onSubmitted,
maxLines: maxLines,
minLines: minLines,
decoration: InputDecoration(labelText: labelText),
);
}
}