在颤振中用于空值的空检查运算符

时间:2021-06-12 09:03:22

标签: flutter dart

我完全是 Flutter 初学者,请帮助我!

Here's the screenshot of the error

'''''''''''''''''''''''''''''''''''''''''''' '

import 'package:flutter/material.dart';

import 'dart:io';

void main() {
  runApp(MaterialApp());
}

class MyApp extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Colors.teal,
        body: SafeArea(
          child: Column (
            children: <Widget>[
              CircleAvatar(
                radius: 50.0,
                backgroundColor: Colors.white,
              )
            ],
          ),
        ),
      ),
    );
  }
}

1 个答案:

答案 0 :(得分:0)

请在 main 方法中返回类。不要返回 MaterialApp。请返回 MyApp,这是您的类。

import 'package:flutter/material.dart';

import 'dart:io';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Colors.teal,
        body: SafeArea(
          child: Column (
            children: <Widget>[
              CircleAvatar(
                radius: 50.0,
                backgroundColor: Colors.white,
              )
            ],
          ),
        ),
      ),
    );
  }
}

并在 test/widget_test.dart 文件中返回。

await tester.pumpWidget(MyApp());