In `QuillEditor` we display paragraphs using `RichText`. The height of a
`RichText` is calculated using a `TextPainter`, basically like this:
```dart
const textSpan = TextSpan(
children: [
TextSpan(text: 'Foo '),
TextSpan(text: 'Bar', style: TextStyle(fontSize: 20, height: 1)),
],
style: TextStyle(color: Colors.black, fontSize: 16),
);
final textPainter = TextPainter(text: textSpan, textDirection: TextDirection.ltr)..layout();
print('Height of textspan: ${textPainter.height}');
// Height of textspan: 20
```
Our code looks basically like this for an empty line:
```dart
const textSpan = TextSpan(
children: [TextSpan(text: '', style: TextStyle(color: Colors.black, fontSize: 20))],
style: null,
);
final textPainter = TextPainter(text: textSpan, textDirection: TextDirection.ltr)..layout();
print('Height of textspan: ${textPainter.height}');
// Height of textspan: 16
```
Now the line wrongly has the height 16 instead of 20, which cuts off the bottom
(see issue #133) from the text. To fix this, I moved the inner `TextSpan` one
layer higher.
Now the problem occurred that a line with several heights has the size of the
strut, because we enforce this size. I couldn't figure out why the strut size
is enforced, so I removed the behavior and a line with multiple sizes is now
displayed correctly.
Closes#133.
* Rebuild editor when keyboard is already open
If the keyboard is already open, but the editor thinks that the
keyboard is not open, the text will not be updated when writing.
This can easily happen if one has a `TabBarView` with two children,
each with an `QuillEditor`, see the code for an example:
<details><summary>Example</summary>
```dart
import 'package:flutter/material.dart';
import 'package:flutter_quill/widgets/controller.dart';
import 'package:flutter_quill/widgets/editor.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late QuillController _controller1;
late QuillController _controller2;
@override
void initState() {
_controller1 = QuillController.basic();
_controller2 = QuillController.basic();
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
title: Text('Flutter Quill tabs demo'),
bottom: TabBar(
tabs: [
Tab(text: 'First'),
Tab(text: 'Second'),
],
),
),
body: TabBarView(
children: [
QuillEditor.basic(controller: _controller1, readOnly: false),
QuillEditor.basic(controller: _controller2, readOnly: false),
],
),
),
),
);
}
}
</details>
<details><summary>Video</summary>
</details>
* Add documentation comment for getOffsetToRevealCursor
* Set initial keyboard visibility
If it's ok, I would spend the day enabling linter rules so that the
codebase is more compliant with [Effective Dart](https://dart.dev/guides/language/effective-dart)
and thus more readable for new developers.
* Remove base64 header from image url
* change removeBase64Header to _standardizeImageUrl and format code
Co-authored-by: Yahia <yahiaibrahim300@gmail.com>