update dart and flutter version

This commit is contained in:
wgh19
2024-04-17 20:55:23 +08:00
parent 32aac42c19
commit bfa25c4b83
13 changed files with 505 additions and 266 deletions

View File

@@ -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

View File

@@ -17,7 +17,7 @@ void main() {
}
class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
@@ -25,9 +25,9 @@ class MyApp extends StatelessWidget {
title: 'flutter_qjs',
debugShowCheckedModeBanner: false,
theme: ThemeData(
appBarTheme: AppBarTheme(brightness: Brightness.dark, elevation: 0),
backgroundColor: Colors.grey[300],
primaryColorBrightness: Brightness.dark,
brightness: Brightness.dark,
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue, brightness: Brightness.dark),
useMaterial3: true
),
routes: {
'home': (BuildContext context) => TestPage(),
@@ -43,8 +43,8 @@ class TestPage extends StatefulWidget {
}
class _TestPageState extends State<TestPage> {
String resp;
IsolateQjs engine;
String? resp;
IsolateQjs? engine;
CodeInputController _controller = CodeInputController(
text: 'import("hello").then(({default: greet}) => greet("world"));');
@@ -79,7 +79,7 @@ class _TestPageState extends State<TestPage> {
onPressed: () async {
await _ensureEngine();
try {
resp = (await engine.evaluate(_controller.text ?? '',
resp = (await engine!.evaluate(_controller.text,
name: "<eval>"))
.toString();
} catch (e) {
@@ -91,7 +91,7 @@ class _TestPageState extends State<TestPage> {
child: Text("reset engine"),
onPressed: () async {
if (engine == null) return;
await engine.close();
await engine!.close();
engine = null;
}),
],