android - 为什么每次在手机上运行新的颤振代码时都会获得默认的颤振示例代码?
问题描述
我正在使用我的安卓手机来运行我的颤振代码。问题是当我运行任何代码时(即与我创建颤振项目时创建的自动生成颤振代码不同),它总是向我显示自动生成颤振代码的输出。每次运行后我都必须重新加载它才能获得新代码的输出。另外,在我将手机与 PC 分离后,手机上的应用程序仍然是自动生成的应用程序。我已经使用了android studio和VS code,但问题仍然存在。我试图创建新项目,但仍然没有运气。
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main() => runApp(new MaterialApp(home: new KeyetWedetApp ())); //The runApp() function takes the given Widget and makes it the root of the widget tree.
class KeyetWedetApp extends StatefulWidget {
@override
_State createState() => new _State();
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.red,
),
home: new KeyetWedetApp(),
darkTheme: new ThemeData(accentColor: Colors.deepPurpleAccent),
);
}
}
class _State extends State<KeyetWedetApp> {
static List _pageSelectorList = <Widget>[
Image.asset('assets/images/balloon.jpeg'),
Image.asset('assets/images/beach.jpeg'),
Image.asset('assets/images/camp.jpeg'),
Image.asset('assets/images/hello.png'),
Image.asset('assets/images/mountain.jpeg')
//TODO Insert our own images which describe what our application will do step by step.
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: new Container(
child: new DefaultTabController(
length: _pageSelectorList.length,
child: Builder(
builder: (BuildContext context) => Padding(
padding: EdgeInsets.fromLTRB(10.0, 30.0, 10.0, 10.0),
child: new Column(
children: <Widget>[
new TabPageSelector(selectedColor: Colors.blue),
new Expanded(
child: IconTheme(
data: IconThemeData(
size: 200.0,
color: Theme.of(context).accentColor,
),
child: TabBarView(
children: _pageSelectorList,
),
)),
new FlatButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HomePage()));
},
child: new Text(
'Let\'s Get Started',
style: new TextStyle(fontSize: 20, color: Color(0xFF757575)),
),
)
],
),
),
),
),
),
),
);
}
}
当我运行这段代码时,它编译并正常运行,没有错误或异常。它是这样的:
- 在调试模式下在 SM G950F 上启动 lib\main.dart...
- √ 内置 build\app\outputs\apk\debug\app-debug.apk。
- D/FlutterActivity(9631):使用启动主题作为普通主题。D/FlutterActivityAndFragmentDelegate(9631):设置 FlutterEngine。D/FlutterActivityAndFragmentDelegate(9631):没有提供首选的 FlutterEngine。为这个 FlutterFragment 创建一个新的 FlutterEngine。D/FlutterActivityAndFragmentDelegate(9631):将FlutterEngine附加到拥有这个Fragment的Activity上。D/FlutterView(9631):附加到 FlutterEngine:io.flutter.embedding.engine.FlutterEngine@133f78d D/FlutterActivityAndFragmentDelegate(9631):执行 Dart 入口点:main,并发送初始路由:/D/ViewRootImpl@bcf80b7MainActivity:MSG_RESIZED_REPORT: frame=Rect(0, 0 - 1080, 2220) ci=Rect(0, 63 - 0, 0) vi=Rect(0, 63 - 0, 0) or=1 D/InputTransport(9631):输入通道构造: fd=99 D/输入方法管理器(9631):
当它最终在我的手机上启动代码时,无论我写什么代码,它总是显示如下所示的颤振示例代码输出:
所以,为了让我的手机显示我的代码,我必须“热重启”它。只有这样我才能得到我的代码的输出。
但是在我停止调试并将手机与 PC 分离后,我手机上的应用程序仍然是颤振示例代码的输出。
总之,我的问题如下:
- 为什么它在第一次运行时不显示我的代码输出。
- 为什么不将我的代码保存在我的设备上,以便当我在手机上打开应用程序时它可以显示我的代码输出。
解决方案
我尝试了很多东西,发现如果我flutter clean
在调试之前在终端上运行它可以解决问题!
推荐阅读
- javascript - 为什么我不能在 package.json 脚本中设置环境值
- kubernetes - minikube 在 win10 上获取带有标签选择器“k8s-app=kube-proxy”的 Pod 时出错
- macos - 如何在 Mac 10.10 上使用包含非 ascii 字符的挂载点挂载目录?
- c++ - 每次调用方法时递增变量
- azure - Azure Http 连接在 5 分钟后中断
- javascript - JS在按钮单击时播放声音
- ios - 如何添加注释注释弹出并保存一些文本 PDFKit iOS11
- workflow - 当作者尝试从 AEM 中的 Dam 资产中删除任何内容时,如何分配工作流?
- r - 按组选择数据框中的最大值
- node.js - NodeJS res.send不返回变量值