new to Flutter so may be missing something that others find 'obvious'. If so - apologies.
I have just started learning Dart/Flutter on Udemy. I've come across a head-scratcher:
When I run one lot of code in an emulator it runs fine, when I run a very similar piece of code it builds without problems but displays absolutely nothing.
I'm writing the code in VSCode and using an emulator from Android Studio.
The code which works is:
// ignore_for_file:prefer_const_constructors
import 'package:flutter/material.dart';
void main() {
runApp(MyDashater());
}
class MyDashater extends StatelessWidget {
const MyDashater({super.key});
// Declare any local variables:
final int colourBlack = 0xff000000,
colourGreen = 0xff119b11,
colourYellow = 0xffffff00;
@override
Widget build(BuildContext context) {
return MaterialApp(
// Turn off the debug mode banner:
debugShowCheckedModeBanner: false,
// Main code block - put everything into the Scaffold:
home: Scaffold(
backgroundColor: Color(colourGreen),
appBar: AppBar(
backgroundColor: Color(colourBlack),
centerTitle: true,
titleTextStyle: TextStyle(color: Color(colourYellow)),
title: Text("My Dashatar App"),
),
body: Center(child: Image.asset('images/mjb_dashatar1.png')),
),
);
}
}
On the emulator this displays: App displaying correctly on emulator
The code which works fine in Windows/any web browser, but not in the emulator is:
// ignore_for_file:prefer_const_constructors
import 'package:flutter/material.dart';
void main() {
runApp(MyDashater());
}
class MyDashater extends StatelessWidget {
const MyDashater({super.key});
// Declare any local variables:
final int colourBlack = 0xff000000,
colourGreen = 0xff119b11,
colourYellow = 0xffffff00;
@override
Widget build(BuildContext context) {
return MaterialApp(
// Turn off the debug mode banner:
debugShowCheckedModeBanner: false,
// Main code block - put everything into the Scaffold:
home: Scaffold(
backgroundColor: Color(colourGreen),
appBar: AppBar(
backgroundColor: Color(colourBlack),
centerTitle: true,
titleTextStyle: TextStyle(color: Color(colourYellow)),
title: Text("My Dashatar App"),
),
body: Center(child: Image.asset('images/mjb_dashatar1.png')),
),
);
}
}
On the emulator this displays: Emulator blank screen
I was expecting the app to launch similarly to how it does when using Windows or a web browser: Working Win 11 version of App
I'd really appreciate any possible pointers. Thank you.
flutter cleanand rerun the app