我使用飞镖创建了仪表板。它没有编译

时间:2019-04-01 22:18:41

标签: android dart flutter

我试图创建一个仪表板。但这不起作用。错误是说“未为_DashboardState类定义MyItems”。我是飞镖新手。请帮忙。我尝试了很多事情,但没有成功。我正在尝试学习飞镖。我在youtube视频中找到了本教程。创作者也遇到了同样的错误,但对他来说效果很好。但是我的模拟器没有运行此代码。

这是我的dashboard.dart文件代码。

import 'package:flutter/material.dart'; 
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';

class Dashboard extends StatefulWidget {
  @override
   _DashboardState createState() => _DashboardState();

}

class _DashboardState extends State<Dashboard>{
  @override
  Widget build(BuildContext context){
    return Scaffold(
      appBar:AppBar(
        title: Text('Menu',
          style: TextStyle(
            color:Colors.white,
        ),
        ),

      ),
      body: StaggeredGridView.count(

          crossAxisCount:2,
          crossAxisSpacing: 12.0,
          mainAxisSpacing: 12.0,
        padding: EdgeInsets.symmetric(horizontal: 16.0, vertical:  8.0),
        children: <Widget>[
          MyItems(Icons.healing, "Health", 0xffed622b),
          MyItems(Icons.fastfood,"Food", 0xffed622b),
          MyItems(Icons.work, "Work", 0xffed622b),
          MyItems(Icons.fitness_center, "Workout", 0xffed622b),

        ],
        staggeredTiles: [
          StaggeredTile.extent(1, 130),
          StaggeredTile.extent(1, 130),
          StaggeredTile.extent(1, 130),
          StaggeredTile.extent(1, 130),
        ]

      ),


    );
  }

这是我的Main.dart代码

import 'package:flutter/material.dart';
import 'dashboard.dart';


void main() => runApp(MyApp());
class MyApp extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Adult Care',
      theme: ThemeData(
        primaryColor: Colors.orange,
      ),
      home: Dashboard(),
    );
  }
}

0 个答案:

没有答案