_TypeError(类型“_Type”不是“Widget?”类型的子类型?

_TypeError (type '_Type' is not a subtype of type 'Widget?')

提问人:Badriya Haddad 提问时间:5/24/2022 最后编辑:Md. Yeasin SheikhBadriya Haddad 更新时间:5/24/2022 访问量:889

问:

大约 6 个月前,代码运行良好,然后发生了此异常。我不知道该怎么做,因为我试图通过使其可为空来修复它,但它不起作用 那我该怎么办? 代码是底部导航栏 这是一张例外的图片:

enter image description here

代码:

    import 'package:blackboard/view/Teacher/AddSheetTeacher.dart';
import 'package:blackboard/view/Teacher/CoursesTeacher.dart';
import 'package:blackboard/view/Teacher/HSTeacher.dart';
import 'package:blackboard/view/Teacher/CoursesTeacher1.dart';
import 'package:flutter/material.dart';
import 'package:blackboard/view/Teacher/HomeScreenTeacher.dart';
import 'package:blackboard/view/Teacher/YourCoursesTeacher.dart';
import 'package:blackboard/view/Teacher/ProfileTeacher.dart';

class dashboard extends StatefulWidget {
  @override
  State<dashboard> createState() => _dashboardState();
}

class _dashboardState extends State<dashboard> {
  int _currentIndex = 0;
  List screens = [CoursesT, HomeScreenTeacher(), HomeScreen()];

  void _updateIndex(int value) {
    setState(() {
      _currentIndex = value;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: screens[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        backgroundColor: Colors.transparent,
        elevation: 0,
        type: BottomNavigationBarType.fixed,
        currentIndex: _currentIndex,
        onTap: (_updateIndex),
        selectedItemColor: Colors.purple.shade700,
        selectedFontSize: 13,
        unselectedFontSize: 13,
        iconSize: 30,
        items: [
          BottomNavigationBarItem(
            label: "HomeScreen",
            icon: Icon(
              Icons.home,
              size: 30,
            ),
          ),
          BottomNavigationBarItem(
            label: "Course",
            icon: Icon(
              Icons.book,
              size: 30,
            ),
          ),
          BottomNavigationBarItem(
            label: "Profile",
            icon: Icon(
              Icons.account_box,
              size: 30,
            ),
          ),
        ],
      ),
    );
  }
}
flutter dart flutter-bottomnavigation

评论


答:

0赞 Md. Yeasin Sheikh 5/24/2022 #1

问题就在这里,需要在里面.CoursesTCoursesT()screens

List<Widget> screens = [CoursesT(), HomeScreenTeacher(), HomeScreen()];