首页 > 解决方案 > 为什么我的代码找不到输入颤振

问题描述

我在运行代码时遇到问题,尽管它已定义但找不到类型。这个Employees1.dart我想创建一个包含员工信息的员工表顺便说一句我添加了员工列表我什至滚动了代码没有错误

import 'package:flutter/material.dart';
import 'package:project1/UI/Emp.dart';
import 'package:project1/UI/empdata.dart';
import 'package:project1/widget/utils.dart';
import 'package:project1/widget/scrollable_widget.dart';

class Employees1 extends StatefulWidget {
  @override
  _Employees1State createState() => _Employees1State();
}

class _Employees1State extends State<Employees1> {
  late List<Emp> empdata;

  @override
  void initState() {
    super.initState();

    this.empdata = List.of(allEmp);
  }
  @override
  Widget build(BuildContext context) => Scaffold(
        body: ScrollableWidget(child: buildDataTable()),
      );

  
      

   Widget buildDataTable() {
     final columns=['Name','Surname','Dob','Address','Tel','Gender','Relationship',
     'Identification','Contract','Start Date','End date','Experience','Poste','Description'
     'Year_Exp','University','Diploma','Salary','Email','Project','Formation'];
     return DataTable(
       columns: getColumns(columns),
       rows: getRows(empdata),
       );
   }
   List<DataColumn> getColumns(List<String> columns){
     return columns.map((String column){
       return DataColumn(
         label: Text(column),
       );

     }
   ).toList();
}
List<DataRow> getRows(List<Emp>empdata) => empdata.map((Emp emp){
  final cells =[emp.Name,emp.Surname,emp.Dob,emp.Adress,emp.Tel,emp.Gender
 ,emp.Relationship,emp.Identification,emp.Contract,emp.Start_Date,emp.End_Date,
 emp.Experience,emp.Post,emp.Description,emp.Year_Exp,emp.University,
 emp.Diploma,emp.Salary,emp.Email,emp.Project,emp.Formation];
  return DataRow(
    cells: Utils.modelBuilder(cells,(index,cell){
      final showEditIcon = index == 0 || index == 1;
      return DataCell(
              Text('$cell'),

    );
    })
  
  );
  

}).toList();

  

  
}

这个具有 Emp 类的 Emp.dart

class Emp{
  final String Name;
  final String Surname;
  final String Dob;
  final String Adress;
  final String Tel;
  final String Gender;
  final String Relationship;
  final String Identification;
  final String Contract;
  final String Start_Date;
  final String End_Date;
  final String Experience;
  final String Post;
  final String Description;
  final String Year_Exp;
  final String University;
  final String Diploma;
  final String Salary;
  final String Email;
  final String Project;
  final String Formation;

  const Emp({
    required this.Name,
    required this.Surname,
    required this.Dob,
    required this.Adress,
    required this.Tel,
    required this.Gender,
    required this.Relationship,
    required this.Identification,
    required this.Contract,
    required this.Start_Date,
    required this.End_Date,
    required this.Experience,
    required this.Post,
    required this.Description,
    required this.Year_Exp,
    required this.University,
    required this.Diploma,
    required this.Salary,
    required this.Email,
    required this.Project,
    required this.Formation,

  });

  Emp copy({
    String? Name,
    String? Surname,
    String? Dob,
    String? Adress,
    String? Tel,
    String? Gender,
    String? Relationship,
    String? Identification,
    String? Contract,
    String? Start_Date,
    String? End_Date,
    String? Experience,
    String? Post,
    String? Description,
    String? Year_Exp,
    String? University,
    String? Diploma,
    String? Salary,
    String? Email,
    String? Project,
    String? Formation,

  }) =>
    Emp(
      Name:Name ?? this.Name,
      Surname:Surname ?? this.Surname,
      Dob: Dob ?? this.Dob,
      Adress: Adress ?? this.Adress,
      Tel: Tel ?? this.Tel,
      Gender: Gender ?? this.Gender,
      Relationship: Relationship ?? this.Gender,
      Identification: Identification ?? this.Identification,
      Contract: Contract ?? this.Contract,
      Start_Date: Start_Date ?? this.Start_Date,
      End_Date: End_Date ?? this.End_Date,
      Experience: Experience ?? this.Experience,
      Post: Post ?? this.Post,
      Description: Description ?? this.Description,
      Year_Exp: Year_Exp ?? this.Year_Exp,
      University: University ?? this.University,
      Diploma: Diploma ?? this.Diploma,
      Salary: Salary ?? this.Salary,
      Email: Email ?? this.Email,
      Project: Project ?? this.Project,
      Formation: Formation ?? this.Formation,


    );
    
}

这是我的终端

lib/UI/Employees1.dart:12:13: Error: Type 'Emp' not found.              
  late List<Emp> empdata;
            ^^^
lib/UI/Employees1.dart:42:28: Error: Type 'Emp' not found.
List<DataRow> getRows(List<Emp>empdata) => empdata.map((Emp emp){
                           ^^^
lib/UI/Employees1.dart:12:13: Error: 'Emp' isn't a type.                
  late List<Emp> empdata;
            ^^^
lib/UI/Employees1.dart:18:28: Error: The getter 'allEmps' isn't defined for the class '_Employees1State'.
 - '_Employees1State' is from 'package:project1/UI/Employees1.dart' ('lib/UI/Employees1.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'allEmps'.
    this.empdata = List.of(allEmps);
                           ^^^^^^^
lib/UI/Employees1.dart:42:28: Error: 'Emp' isn't a type.
List<DataRow> getRows(List<Emp>empdata) => empdata.map((Emp emp){
                           ^^^
lib/UI/Employees1.dart:42:57: Error: 'Emp' isn't a type.        
List<DataRow> getRows(List<Emp>empdata) => empdata.map((Emp emp){
                                                        ^^^
lib/UI/Employees1.dart:59:4: Error: A value of type 'List<dynamic>' can't be 
returned from a function with return type 'List<DataRow>'.
 - 'List' is from 'dart:core'.
 - 'DataRow' is from 'package:flutter/src/material/data_table.dart' ('/C:/flutter/packages/flutter/lib/src/material/data_table.dart').
}).toList();
   ^
                                                                             
                                                                             
FAILURE: Build failed with an exception.

* Where:
Script 'C:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1035  

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\flutter\bin\flutter.bat'' finished with non-zero exit 
value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.ug option to get more log output. Run with --scan to get full insights.      

* Get more help at https://help.gradle.org

BUILD FAILED in 19s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done                        21,0s     
Exception: Gradle task assembleDebug failed with exit code 1

所有代码都没有任何错误,但它无法运行

我是 Flutter 的新手,任何帮助谢谢 :)

标签: flutter

解决方案


推荐阅读