【发布时间】:2021-09-24 12:02:21
【问题描述】:
我正在尝试为 Flutter 界面编写 UI 代码,并且在我添加“ListView”小部件之前一切顺利。我试图编译代码,它说构建成功完成。但是当我运行它时,虚拟 Android 屏幕加载了一点,然后变成了一片漆黑。我尝试了几次,但没有成功。请任何人都可以帮助我使用此代码:
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Stateful Clicker Counter',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Clicker Counter Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 50.0),
child: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(
Icons.play_arrow,
size: 50.0,
), //Icon
), //Floatingactionbutton
), //Padding
Padding(
padding: const EdgeInsets.only(top: 50.0),
child: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(
Icons.pause,
size: 50.0,
), //Icon
), //Floatingactionbutton
), //Padding
Padding(
padding: const EdgeInsets.only(top: 50.0),
child: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(
Icons.mic,
size: 50.0,
), //Icon
), //FloatingactionButton
), //Padding
ListView(
padding: const EdgeInsets.all(5.0),
children: <Widget>[
Container(
height: 30.0,
color: Colors.amber[600],
child: const Center(
child: Text(
'Entry A',
), //Text
), //Center
), //Container
Container(
height: 30.0,
color: Colors.amber[500],
child: const Center(
child: Text(
'Entry B',
), //Text
), //Center
), //Container
Container(
height: 30.0,
color: Colors.amber[100],
child: const Center(
child: Text(
'Entry C',
), //Text
), //Center
), //Container
], //End of Widget tree
), //ListView
], //End of submain Widget Tree
), //Row
], //End of Main Widget Tree
), //Column
), //Main Center
); //Scaffold
}
}
P.S:我刚开始使用 Flutter,所以有些事情可能看起来没有必要
【问题讨论】:
-
可以添加错误日志吗?