Solution 1 :
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.
- Preferred solution:
Go to menu in Visual Studio Code, File -> Click ‘Auto save’. So that you don’t have to save changes each time, it will be auto-saved.
Solution 2 :
I tried many things and found out that if I run flutter clean
on the terminal before going into debugging it solves the problem!
Problem :
I am using my android phone to run my flutter code. The problem is when i run any code(i.e. 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. I have to reload it after each run to get the output of my new code. Plus, after i detached my phone from my PC the app i get on my phone is still the auto generated one. I have used both android studio and VS code but the problem still persists. 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 libmain.dart on SM G950F in debug mode…
- √ Built buildappoutputsapkdebugapp-debug.apk.
- D/FlutterActivity( 9631): Using the launch theme as normal theme.
D/FlutterActivityAndFragmentDelegate( 9631): Setting up FlutterEngine.
D/FlutterActivityAndFragmentDelegate( 9631): No preferred FlutterEngine was provided. Creating a new FlutterEngine for this FlutterFragment.
D/FlutterActivityAndFragmentDelegate( 9631): Attaching FlutterEngine to the Activity that owns this Fragment.
D/FlutterView( 9631): Attaching to a FlutterEngine: [email protected]
D/FlutterActivityAndFragmentDelegate( 9631): Executing Dart entrypoint: main, and sending initial route: /
D/[email protected]: 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() [email protected][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.
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:
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.
This is my code’s output which comes after i hot restarted it
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.
In summary my questions are the following:
- Why isn’t it showing my code’s output on the first run.
- 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.
Comments
Comment posted by Abdelbaki Boukerche
Can you post your
Comment posted by Simon Hutton
… and also maybe post the output from your run console. Are you getting messages saying “Launching… on…”, “Built…”, “Installing…” etc? did your code actually compile, or is your phone just rerunning the previously installed code (i.e. the default example app).
Comment posted by Harsh Mehta
Try this: – When you are able to run your code on the app, do not terminate your process or the app in your device. While your app is running, detach your phone without terminating the process. See if the app is still running your desired code. – If the app runs the desired code, then try terminating the app and then start it again and let me know if it shows the default starter app for flutter
Comment posted by abene42
@Harsh_Mehta I tried it but is still shows the default starter app 🙁