简体   繁体   English

为什么我每次在手机上运行新的 flutter 代码时都会得到默认的 flutter 示例代码?

[英]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:它是这样的:

  • Launching lib\main.dart on SM G950F in debug mode...在调试模式下在 SM G950F 上启动 lib\main.dart...
  • √ Built build\app\outputs\apk\debug\app-debug.apk. √ 内置build\app\outputs\apk\debug\app-debug.apk。
  • D/FlutterActivity( 9631): Using the launch theme as normal theme. D/FlutterActivity(9631):使用启动主题作为普通主题。 D/FlutterActivityAndFragmentDelegate( 9631): Setting up FlutterEngine. D/FlutterActivityAndFragmentDelegate(9631):设置 FlutterEngine。 D/FlutterActivityAndFragmentDelegate( 9631): No preferred FlutterEngine was provided. D/FlutterActivityAndFragmentDelegate(9631):没有提供首选的FlutterEngine。 Creating a new FlutterEngine for this FlutterFragment.为此 FlutterFragment 创建一个新的 FlutterEngine。 D/FlutterActivityAndFragmentDelegate( 9631): Attaching FlutterEngine to the Activity that owns this Fragment. D/FlutterActivityAndFragmentDelegate( 9631) :将 FlutterEngine 附加到拥有此 Fragment 的 Activity。 D/FlutterView( 9631): Attaching to a FlutterEngine: io.flutter.embedding.engine.FlutterEngine@133f78d D/FlutterActivityAndFragmentDelegate( 9631): Executing Dart entrypoint: main, and sending initial route: / 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): Input channel constructed: fd=99 D/InputMethodManager( 9631): prepareNavigationBarInfo() DecorView@13938bf[MainActivity] D/InputMethodManager( 9631): getNavigationBarColor() -855310 V/InputMethodManager( 9631): Starting input: tba=com.keyetwedet.keyet_wedet ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true, NavVisible: true, NavTrans: false D/InputMethodManager( 9631): startInputInner - Id: 0 E/AccessibilityBridge( 9631): VirtualView node must not be the root node. D/FlutterView(9631):附加到FlutterEngine:io.flutter888888888888888888888888888DENGING.ENGINE.FLUTTERNENGENGENCENT @133F78D D/FLUTTERATTIVENTIVE和FLUTTERACTIVENTIVE和FLUTTERACTIVITION and FRUTTEVITION and FRATTIVENTIVENDENTIND_ NOSTERTIONT(9631) 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/InputMethodManager(9631):prepareNavigationBarInfo() DecorView@13938bf[MainActivity] D/InputMethodManager(9631):getNavigationBarColor()-855310 V/InputMethodManager(9631):开始输入:tba=com.keyetwedet.keyet_wedet ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true,NavVisible:true,NavTrans:false D/InputMethodManager(9631):startInputInner - Id:0 E/AccessibilityBridge(9631):VirtualView 节点不能是根节点。

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:总之,我的问题如下:

  1. Why isn't it showing my code's output on the first run.为什么它在第一次运行时不显示我的代码 output。
  2. Why isn't it saving my code on my device so that when i open the app on my phone it could show me the output of my code.为什么它不将我的代码保存在我的设备上,以便当我在手机上打开该应用程序时,它可以显示我的代码 output。

I'm also facing the same issue.我也面临同样的问题。 But I found what went wrong.但是我发现出了什么问题。

  • Problem:问题:

I didn't save the code after making changes in default example.在默认示例中进行更改后,我没有保存代码。

  • Solution:解决方案:

Press CTRL+s to save each time any change is made in code.每次在代码中进行任何更改时,按 CTRL+s 保存。

  • Preferred solution:首选解决方案:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM