错误 "FormatException: Unexpected character (at character 1)" 即使在默认的默认 flutter web 项目中
Error "FormatException: Unexpected character (at character 1)" even in default default flutter web project
每当我创建一个新的 flutter web 项目时,它都会给我同样的错误:Unexpected Character (at character 1)
.
当我 运行 webdev serve
时,它给出一个空白屏幕并停止。
并且,在 webdev 守护程序上我得到了错误。
代码我没有做任何改动,原样执行,即默认的flutter web项目
我已经卸载并重新安装,尝试了 flutter clean,但是 none 可以正常工作:
详情如下:
Unhandled exception:
FormatException: Unexpected character (at character 1)
Not Found
^
#0 _ChunkedJsonParser.fail (dart:convert-patch/convert_patch.dart:1392:5)
#1 _ChunkedJsonParser.parseNumber (dart:convert-patch/convert_patch.dart:1259:9)
#2 _ChunkedJsonParser.parse (dart:convert-patch/convert_patch.dart:924:22)
#3 _parseJson (dart:convert-patch/convert_patch.dart:29:10)
#4 JsonDecoder.convert (dart:convert/json.dart:493:36)
#5 JsonCodec.decode (dart:convert/json.dart:151:41)
#6 jsonDecode (dart:convert/json.dart:94:10)
#7 parse (package:source_maps/parser.dart:27:15)
#8 Sources.scriptParsed (package:dwds/src/debugging/sources.dart:62:19)
<asynchronous suspension>
#9 _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#10 CastStreamSubscription._onData (dart:_internal/async_cast.dart:81:11)
#11 _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#12 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#13 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#14 _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:68:11)
#15 _EventSinkWrapper.add (dart:async/stream_transformers.dart:15:11)
#16 WipDomain.eventStream.<anonymous closure>.<anonymous closure> (package:webkit_inspection_protocol/webkit_inspection_protocol.dart:301:26)
#17 _HandlerEventSink.add (dart:async/stream_transformers.dart:228:7)
#18 _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:120:24)
#19 _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#20 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#21 _DelayedData.perform (dart:async/stream_impl.dart:591:14)
#22 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:707:11)
#23 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:667:7)
#24 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#25 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#26 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:116:13)
#27 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:173:5)
pub failed (255)
我的main.dart
import 'package:flutter_web/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatelessWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
Widget build(BuildContext context) {
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (choose the "Toggle Debug Paint" action
// from the Flutter Inspector in Android Studio, or the "Toggle Debug
// Paint" command in Visual Studio Code) to see the wireframe for each
// widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Hello, World!',
),
],
),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
https://github.com/ipshitag/hello_world/tree/master/helloworld
这是 Windows 上的一个 webdev 错误,已在 webdev v2.5.0 中修复:
运行 pub global activate webdev
更新到最新版本。
每当我创建一个新的 flutter web 项目时,它都会给我同样的错误:Unexpected Character (at character 1)
.
当我 运行 webdev serve
时,它给出一个空白屏幕并停止。
并且,在 webdev 守护程序上我得到了错误。
代码我没有做任何改动,原样执行,即默认的flutter web项目
我已经卸载并重新安装,尝试了 flutter clean,但是 none 可以正常工作:
详情如下:
Unhandled exception:
FormatException: Unexpected character (at character 1)
Not Found
^
#0 _ChunkedJsonParser.fail (dart:convert-patch/convert_patch.dart:1392:5)
#1 _ChunkedJsonParser.parseNumber (dart:convert-patch/convert_patch.dart:1259:9)
#2 _ChunkedJsonParser.parse (dart:convert-patch/convert_patch.dart:924:22)
#3 _parseJson (dart:convert-patch/convert_patch.dart:29:10)
#4 JsonDecoder.convert (dart:convert/json.dart:493:36)
#5 JsonCodec.decode (dart:convert/json.dart:151:41)
#6 jsonDecode (dart:convert/json.dart:94:10)
#7 parse (package:source_maps/parser.dart:27:15)
#8 Sources.scriptParsed (package:dwds/src/debugging/sources.dart:62:19)
<asynchronous suspension>
#9 _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#10 CastStreamSubscription._onData (dart:_internal/async_cast.dart:81:11)
#11 _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#12 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#13 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#14 _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:68:11)
#15 _EventSinkWrapper.add (dart:async/stream_transformers.dart:15:11)
#16 WipDomain.eventStream.<anonymous closure>.<anonymous closure> (package:webkit_inspection_protocol/webkit_inspection_protocol.dart:301:26)
#17 _HandlerEventSink.add (dart:async/stream_transformers.dart:228:7)
#18 _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:120:24)
#19 _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#20 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#21 _DelayedData.perform (dart:async/stream_impl.dart:591:14)
#22 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:707:11)
#23 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:667:7)
#24 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#25 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#26 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:116:13)
#27 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:173:5)
pub failed (255)
我的main.dart
import 'package:flutter_web/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatelessWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
Widget build(BuildContext context) {
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (choose the "Toggle Debug Paint" action
// from the Flutter Inspector in Android Studio, or the "Toggle Debug
// Paint" command in Visual Studio Code) to see the wireframe for each
// widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Hello, World!',
),
],
),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
https://github.com/ipshitag/hello_world/tree/master/helloworld
这是 Windows 上的一个 webdev 错误,已在 webdev v2.5.0 中修复:
运行 pub global activate webdev
更新到最新版本。