[英]Why am i getting the default flutter example code every time i run my new flutter code on my phone?
I am using my android phone to run my flutter code.我正在使用我的 android 手机来运行我的 flutter 代码。 The problem is when i run any code(ie different from the auto generated flutter code that is created when i create a flutter project)it always shows me the output of the auto generated flutter code.
问题是当我运行任何代码时(即不同于我创建 flutter 项目时创建的自动生成的 flutter 代码)它总是向我显示自动生成的 flutter 代码的 output。 I have to reload it after each run to get the output of my new code.
我必须在每次运行后重新加载它才能获得新代码的 output。 Plus, after i detached my phone from my PC the app i get on my phone is still the auto generated one.
另外,在我将手机与 PC 分离后,我在手机上获得的应用程序仍然是自动生成的应用程序。 I have used both android studio and VS code but the problem still persists.
我已经使用了 android studio 和 VS code,但问题仍然存在。 I have tried to create new project but still no luck.
我试图创建新项目,但仍然没有成功。
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)),
),
)
],
),
),
),
),
),
),
);
}
}
When i run the this code, it compile and run normally without error or exceptions.当我运行这段代码时,它编译并正常运行,没有错误或异常。 It goes like this:
它是这样的:
And when it finally launches the code on my phone, no matter what code i wrote, it always show the flutter sample code output like this:当它最终在我的手机上启动代码时,无论我写什么代码,它总是显示 flutter 示例代码 output,如下所示:
This is what i always get on the first run这是我总是在第一次跑步时得到的
So, in order to get my phone showing my code i have to "hot restart" it.所以,为了让我的手机显示我的代码,我必须“热重启”它。 Only then i will get the output of my code.
只有这样我才能得到我的代码的 output。
This is my code's output which comes after i hot restarted it这是我的代码 output,它是在我热重启后出现的
But after i stopped the debugging and detached my phone from my PC, the app i get on my phone is still the output of the flutter sample code.但是在我停止调试并将手机与电脑分离后,我在手机上获得的应用程序仍然是 flutter 示例代码中的 output。
In summary my questions are the following:总之,我的问题如下:
I'm also facing the same issue.我也面临同样的问题。 But I found what went wrong.
但是我发现出了什么问题。
I didn't save the code after making changes in default example.在默认示例中进行更改后,我没有保存代码。
Press CTRL+s to save each time any change is made in code.每次在代码中进行任何更改时,按 CTRL+s 保存。
Go to menu in Visual Studio Code, File -> Click 'Auto save'. Go 到 Visual Studio Code 中的菜单,文件 -> 单击“自动保存”。 So that you don't have to save changes each time, it will be auto-saved.
这样您就不必每次都保存更改,它会自动保存。
我尝试了很多东西,发现如果我在调试之前在终端上运行flutter clean
就可以解决问题!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.