即使代码更改后,Flutter 仍保持 运行 默认值 "Counter App"(Windows App)
Flutter keeps running default "Counter App" even after Code change(Windows App)
(Flutter -WindowsAPP - Flutter 1.26.0-1.0.pre • 频道开发 • https://github.com/flutter/flutter.git
框架 • 修订版 63062a6443(12 天前) • 2020-12-13 23:19:13 +0800
引擎 • 修订版 4797b06652
工具 • Dart 2.12.0(内部版本 2.12.0-141.0.dev)
).
Flutter 保留 运行 默认的 Counter App ,即使代码已更改为 StreamBuilder App。
lib folder
中只有一个main.dart
(build/test文件夹中没有额外的“Counter APP”代码),Run-edit configuration
指向这个文件。
但是,在删除默认“Counter App”(之前编译)的代码,并将其替换为 Streambuilder 应用程序的代码并保存 'main.dart' 后,Counter App 仍然 运行的.
尝试重新启动 Android Studio 以及热 reload/hot 重新启动,但 Counter App 仍在运行。
图片
终端
flutter run -d windows
代码
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
/// This is the main application widget.
class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: MyStatefulWidget(),
);
}
}
/// This is the stateful widget that the main application instantiates.
class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key}) : super(key: key);
@override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}
/// This is the private State class that goes with MyStatefulWidget.
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
Stream<int> _bids = (() async* {
await Future<void>.delayed(Duration(seconds: 1));
yield 1;
await Future<void>.delayed(Duration(seconds: 1));
})();
Widget build(BuildContext context) {
return DefaultTextStyle(
style: Theme.of(context).textTheme.headline2,
textAlign: TextAlign.center,
child: Container(
alignment: FractionalOffset.center,
color: Colors.white,
child: StreamBuilder<int>(
stream: _bids,
builder: (BuildContext context, AsyncSnapshot<int> snapshot) {
List<Widget> children;
if (snapshot.hasError) {
children = <Widget>[
Icon(
Icons.error_outline,
color: Colors.red,
size: 60,
),
Padding(
padding: const EdgeInsets.only(top: 16),
child: Text('Error: ${snapshot.error}'),
)
];
} else {
switch (snapshot.connectionState) {
case ConnectionState.none:
children = <Widget>[
Icon(
Icons.info,
color: Colors.blue,
size: 60,
),
const Padding(
padding: EdgeInsets.only(top: 16),
child: Text('Select a lot'),
)
];
break;
case ConnectionState.waiting:
children = <Widget>[
SizedBox(
child: const CircularProgressIndicator(),
width: 60,
height: 60,
),
const Padding(
padding: EdgeInsets.only(top: 16),
child: Text('Awaiting bids...'),
)
];
break;
case ConnectionState.active:
children = <Widget>[
Icon(
Icons.check_circle_outline,
color: Colors.green,
size: 60,
),
Padding(
padding: const EdgeInsets.only(top: 16),
child: Text('$${snapshot.data}'),
)
];
break;
case ConnectionState.done:
children = <Widget>[
Icon(
Icons.info,
color: Colors.blue,
size: 60,
),
Padding(
padding: const EdgeInsets.only(top: 16),
child: Text('$${snapshot.data} (closed)'),
)
];
break;
}
}
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: children,
);
},
),
),
);
}
}
EDIT-1
即使在 flutter clean 之后,运行 上面的脚本 still runs the default Counter app.
终端
F:\Flutter\flutter_windows\windows_test_1>flutter clean
Deleting build... 784ms
Deleting .dart_tool... 9ms
Deleting Generated.xcconfig... 1ms
Deleting flutter_export_environment.sh... 0ms
Deleting ephemeral... 22ms
Deleting .flutter-plugins-dependencies... 2ms
Deleting .flutter-plugins... 0ms
F:\Flutter\flutter_windows\windows_test_1>flutter run -d windows
Running "flutter pub get" in windows_test_1... 433ms
Launching lib\main.dart on Windows in debug mode...
Building Windows application...
Syncing files to device Windows... 104ms
这个 Flutter Windows 应用程序是第一次创建(安装了所需的依赖项)。
创建一个全新的项目解决了这个问题。
(Flutter -WindowsAPP - Flutter 1.26.0-1.0.pre • 频道开发 • https://github.com/flutter/flutter.git 框架 • 修订版 63062a6443(12 天前) • 2020-12-13 23:19:13 +0800 引擎 • 修订版 4797b06652 工具 • Dart 2.12.0(内部版本 2.12.0-141.0.dev) ).
Flutter 保留 运行 默认的 Counter App ,即使代码已更改为 StreamBuilder App。
lib folder
中只有一个main.dart
(build/test文件夹中没有额外的“Counter APP”代码),Run-edit configuration
指向这个文件。
但是,在删除默认“Counter App”(之前编译)的代码,并将其替换为 Streambuilder 应用程序的代码并保存 'main.dart' 后,Counter App 仍然 运行的.
尝试重新启动 Android Studio 以及热 reload/hot 重新启动,但 Counter App 仍在运行。
图片
终端
flutter run -d windows
代码
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
/// This is the main application widget.
class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: MyStatefulWidget(),
);
}
}
/// This is the stateful widget that the main application instantiates.
class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key}) : super(key: key);
@override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}
/// This is the private State class that goes with MyStatefulWidget.
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
Stream<int> _bids = (() async* {
await Future<void>.delayed(Duration(seconds: 1));
yield 1;
await Future<void>.delayed(Duration(seconds: 1));
})();
Widget build(BuildContext context) {
return DefaultTextStyle(
style: Theme.of(context).textTheme.headline2,
textAlign: TextAlign.center,
child: Container(
alignment: FractionalOffset.center,
color: Colors.white,
child: StreamBuilder<int>(
stream: _bids,
builder: (BuildContext context, AsyncSnapshot<int> snapshot) {
List<Widget> children;
if (snapshot.hasError) {
children = <Widget>[
Icon(
Icons.error_outline,
color: Colors.red,
size: 60,
),
Padding(
padding: const EdgeInsets.only(top: 16),
child: Text('Error: ${snapshot.error}'),
)
];
} else {
switch (snapshot.connectionState) {
case ConnectionState.none:
children = <Widget>[
Icon(
Icons.info,
color: Colors.blue,
size: 60,
),
const Padding(
padding: EdgeInsets.only(top: 16),
child: Text('Select a lot'),
)
];
break;
case ConnectionState.waiting:
children = <Widget>[
SizedBox(
child: const CircularProgressIndicator(),
width: 60,
height: 60,
),
const Padding(
padding: EdgeInsets.only(top: 16),
child: Text('Awaiting bids...'),
)
];
break;
case ConnectionState.active:
children = <Widget>[
Icon(
Icons.check_circle_outline,
color: Colors.green,
size: 60,
),
Padding(
padding: const EdgeInsets.only(top: 16),
child: Text('$${snapshot.data}'),
)
];
break;
case ConnectionState.done:
children = <Widget>[
Icon(
Icons.info,
color: Colors.blue,
size: 60,
),
Padding(
padding: const EdgeInsets.only(top: 16),
child: Text('$${snapshot.data} (closed)'),
)
];
break;
}
}
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: children,
);
},
),
),
);
}
}
EDIT-1
即使在 flutter clean 之后,运行 上面的脚本 still runs the default Counter app.
终端
F:\Flutter\flutter_windows\windows_test_1>flutter clean
Deleting build... 784ms
Deleting .dart_tool... 9ms
Deleting Generated.xcconfig... 1ms
Deleting flutter_export_environment.sh... 0ms
Deleting ephemeral... 22ms
Deleting .flutter-plugins-dependencies... 2ms
Deleting .flutter-plugins... 0ms
F:\Flutter\flutter_windows\windows_test_1>flutter run -d windows
Running "flutter pub get" in windows_test_1... 433ms
Launching lib\main.dart on Windows in debug mode...
Building Windows application...
Syncing files to device Windows... 104ms
这个 Flutter Windows 应用程序是第一次创建(安装了所需的依赖项)。
创建一个全新的项目解决了这个问题。