当我在扑动模拟器上运行应用程序时出现白屏?



当我通过android模拟器在flutter上运行我的应用程序时,我有一个问题。它只是一个白屏,我根本无法与我的应用程序交互。我分享了主餐。飞镖,主页。请你考虑一下。谢谢你

编辑:现在是黑屏编辑2:过去的10分钟都是这样的

这是main.dart

import 'package:flutter/material.dart';
import 'package:flutter_application_1/widgets/stock_management.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My App',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const HomePage(),
);
}
}
class _HomePageState extends State<HomePage> {
int counter = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('My Home Page'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('You have pressed the button this many times:',),
Text('$counter', style: Theme.of(context).textTheme.headline4),
ElevatedButton(
onPressed: () {
setState(() {
counter++;
});
},
child: const Text('Increment'),
),
],
),
),
);
}
}

这是home_page.dart

import 'package:flutter/material.dart';
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('My Home Page'),
),
body: const Center(
child: Text('Welcome to my home page!'),
),
);
}
}

我认为对于计数器函数,您应该将主页定义为有状态的小部件,因为每次您按增量按钮时,您都会更新正在传递的计数器值的状态。

尝试您的主。飞镖文件:

import 'package:flutter/material.dart';
import 'home_page.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My App',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
);
}
}

和你的主页。Dart文件,试试:

import 'package:flutter/material.dart';

class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int counter = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('My Home Page'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('You have pressed the button this many times:',),
Text('$counter', style: Theme.of(context).textTheme.headline4),
ElevatedButton(
onPressed: () {
setState(() {
counter++;
});
},
child: const Text('Increment'),
),
],
),
),
);
}
}

不太确定你从模拟器得到的白屏/黑屏是怎么回事。你可以试着用更多关于你的开发环境的细节来截图它,有人应该能够帮助你。

相关内容

  • 没有找到相关文章

最新更新