mirror of
https://github.com/wgh136/flutter_qjs.git
synced 2025-09-27 21:37:24 +00:00
update dart and flutter version
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
* @LastEditTime: 2020-08-02 12:39:26
|
||||
*/
|
||||
import 'dart:math';
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_highlight/themes/a11y-light.dart';
|
||||
@@ -30,16 +29,16 @@ List<TextSpan> _convert(String code) {
|
||||
stack.add(currentSpans);
|
||||
currentSpans = tmp;
|
||||
|
||||
node.children.forEach((n) {
|
||||
node.children!.forEach((n) {
|
||||
_traverse(n);
|
||||
if (n == node.children.last) {
|
||||
if (n == node.children!.last) {
|
||||
currentSpans = stack.isEmpty ? spans : stack.removeLast();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (var node in nodes) {
|
||||
for (var node in nodes!) {
|
||||
_traverse(node);
|
||||
}
|
||||
|
||||
@@ -47,18 +46,19 @@ List<TextSpan> _convert(String code) {
|
||||
}
|
||||
|
||||
class CodeInputController extends TextEditingController {
|
||||
CodeInputController({String text}) : super(text: text);
|
||||
CodeInputController({required String text}) : super(text: text);
|
||||
|
||||
TextSpan oldSpan = TextSpan();
|
||||
Future<void> spanCall;
|
||||
Future<void>? spanCall;
|
||||
|
||||
@override
|
||||
TextSpan buildTextSpan(
|
||||
{@required BuildContext context, TextStyle style, bool withComposing}) {
|
||||
{required BuildContext context, TextStyle? style,
|
||||
bool? withComposing}) {
|
||||
String oldText = oldSpan.toPlainText();
|
||||
String newText = value.text;
|
||||
if (oldText == newText) return oldSpan;
|
||||
(spanCall?.timeout(Duration.zero) ?? Future.value())
|
||||
spanCall?.timeout(Duration.zero)
|
||||
.then((_) => spanCall = compute(_convert, value.text).then((lsSpan) {
|
||||
TextSpan newSpan = TextSpan(style: style, children: lsSpan);
|
||||
if (newSpan.toPlainText() == value.text) oldSpan = newSpan;
|
||||
@@ -70,7 +70,7 @@ class CodeInputController extends TextEditingController {
|
||||
int splitAt = value.selection.start;
|
||||
if (splitAt < 0) splitAt = newText.length ~/ 2;
|
||||
int start = 0;
|
||||
InlineSpan leftSpan;
|
||||
InlineSpan? leftSpan;
|
||||
oldSpan.children?.indexWhere((element) {
|
||||
String elementText = element.toPlainText();
|
||||
if (start + elementText.length > splitAt ||
|
||||
@@ -78,14 +78,14 @@ class CodeInputController extends TextEditingController {
|
||||
leftSpan = element;
|
||||
return true;
|
||||
}
|
||||
beforeSpans.add(element);
|
||||
beforeSpans.add(element as TextSpan);
|
||||
start += elementText.length;
|
||||
return false;
|
||||
});
|
||||
List<TextSpan> endSpans = [];
|
||||
int end = 0;
|
||||
InlineSpan rightSpan;
|
||||
oldSpan.children?.sublist(beforeSpans.length)?.lastIndexWhere((element) {
|
||||
InlineSpan? rightSpan;
|
||||
oldSpan.children?.sublist(beforeSpans.length).lastIndexWhere((element) {
|
||||
String elementText = element.toPlainText();
|
||||
if (splitAt + end + elementText.length >= newText.length ||
|
||||
!newText
|
||||
@@ -94,7 +94,7 @@ class CodeInputController extends TextEditingController {
|
||||
rightSpan = element;
|
||||
return true;
|
||||
}
|
||||
endSpans.add(element);
|
||||
endSpans.add(element as TextSpan);
|
||||
end += elementText.length;
|
||||
return false;
|
||||
});
|
||||
@@ -102,8 +102,8 @@ class CodeInputController extends TextEditingController {
|
||||
return TextSpan(style: style, children: [
|
||||
...beforeSpans,
|
||||
TextSpan(
|
||||
style: leftSpan != null && leftSpan == rightSpan
|
||||
? leftSpan.style
|
||||
style: leftSpan != null && leftSpan == rightSpan!
|
||||
? leftSpan!.style
|
||||
: style,
|
||||
text: newText.substring(start, max(start, newText.length - end))),
|
||||
...endSpans.reversed
|
||||
|
Reference in New Issue
Block a user