参数类型 'num' 不能分配给参数类型 'int?

时间:2021-07-16 06:15:57

标签: flutter dart

你好朋友,我尝试在未来的构建器列表视图中使用 sqlite 制作待办事项列表应用程序 当我尝试使用 itemcout:1+snapshot.data.lenghth 时,我收到此错误“无法将参数类型 'num' 分配给参数类型 'int?”专家请帮助我正在关注https://www.youtube.com/watch?v=45WbiVIp2ls&list=PLW9-80IN43dlvfnira5Ty3-9Mq21SP3eN&index=7&ab_channel=TechnicalSolutions此视频以制作待办事项列表的问题是什么? check this picture also

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:untitled1/helper/Databasehelper.dart';
import 'package:untitled1/models/task_model.dart';
import 'package:untitled1/sacreen/tasksacreen.dart';

class Todlistsacreen extends StatefulWidget {
  const Todlistsacreen({Key? key}) : super(key: key);

  @override
  _TodlistsacreenState createState() => _TodlistsacreenState();
}

class _TodlistsacreenState extends State<Todlistsacreen> {

late Future<List<Task>> _tasklist;


@override
void initState() {
  super.initState();
_updateTasklist();
}
_updateTasklist(){
  setState(() {
_tasklist=Databasehelper.instance.getTaskList();

  });
}

  Widget _buildlist(int index){
return ListTile(
  title: Text('Task Title'),
  subtitle: Text(
    'oct 2,2019 High  '
  ),

 trailing: Checkbox(
   onChanged: (value){
     print(value);
     },
   value: true,

   activeColor: Theme.of(context).primaryColor,
 ),

);

}
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton:FloatingActionButton(
        backgroundColor: Theme.of(context).primaryColor,
        child: Icon(Icons.add),
        onPressed: () {
          Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) => new AddTask()));
          
      },

      ),
      body:Padding(
        padding: EdgeInsets.all(0),
        child: FutureBuilder(
          future: _tasklist,
          builder: (context,snapshot) {

            if(!snapshot.hasData){
              return Center(
                child: CircularProgressIndicator(),
              );
            }

          return ListView.builder(
        itemCount: 1+snapshot.data.length,
          padding: EdgeInsets.symmetric(vertical: 80.0),


              itemBuilder:(BuildContext contex,int index){
              if(index==0){
             return  Padding(
                padding:EdgeInsets.symmetric(horizontal:80.0,vertical: 20.0),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start, children:<Widget> [
                  Text('Reminder',style:TextStyle(
                      fontSize: 40,
                      color: Colors.black,
                      fontWeight: FontWeight.bold
                  ),),
                  SizedBox(height: 20,),
                  Text('1 of 10',style: TextStyle(
                      fontSize: 22,
                      fontWeight: FontWeight.w600,
                      color: Colors.grey
                  ),)

                ],
                ),
              );

            }
              else{
              return _buildlist(index);
              }




            }


          );
          },
        ),
      ),
    );
  }
}

1 个答案:

答案 0 :(得分:1)

对我来说这是有效的

builder: (context, AsyncSnapshot snapshot) {
                if (!snapshot.hasData) {
                  return Center(
                    child: CircularProgressIndicator(),
                  );

itemCount: snapshot.data.length + 1 ,