'_TypeError'类型不是'bool'类型的子类型

时间:2020-08-25 19:10:46

标签: flutter flutter-layout flutter-animation

最近我从代码中得到了这种类型的问题。这里有两种类型的问题。第一个问题是type '_TypeError' is not a subtype of type 'bool',这就是问题。第二个问题是A RenderFlex overflowed by 99535 pixels on the bottom.,这是我面临的两种类型的问题。我不明白问题出在哪里。因此,出于这个原因,我会将所有代码都放在这里。

这是问题日志。

════════ Exception caught by rendering library ═══════════════════════════════

A RenderFlex overflowed by 99535 pixels on the bottom.
The relevant error-causing widget was
    Column 
lib/partials/myclients.dart:31
════════════════════════════════════════════════════════════════

Another exception was thrown: type '_TypeError' is not a subtype of type 'bool'

════════ Exception caught by widgets library ══════════════════════════

type '_TypeError' is not a subtype of type 'bool'
The relevant error-causing widget was
    FutureBuilder<List<MyClient>> 
lib/partials/myclients.dart:63
═══════════════════════════════════════════════════════════════

这是我的屏幕页面。 MyClientPage屏幕

import 'package:flutter/material.dart';

class MyClentsPage extends StatefulWidget {
  @override
  _MyClentsPageState createState() => _MyClentsPageState();
}

class _MyClentsPageState extends State<MyClentsPage>
    with SingleTickerProviderStateMixin {
  AnimationController _controller;
  TextEditingController searchController = TextEditingController();
  MyClient myClient = MyClient();

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(vsync: this);
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: <Widget>[
          // MyPerformChart(),
          // Text("Quick Performance checker"),
          // PerformDataList(),
          searchBar(),
          dataListView(),
        ],
      ),
    );
  }

  Padding searchBar() {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: TextField(
        decoration: InputDecoration(
          prefixIcon: Icon(Icons.search),
          hintText: 'Search By Name',
        ),
        controller: searchController,
        onChanged: (value) {
          print(value);
        },
        onSubmitted: (value) {
          searchController.text = value;
        },
      ),
    );
  }

  Widget dataListView() {
    return FutureBuilder<List<MyClient>>(
      future: myClient.fetchClients(),
      builder: (context, snapshot) {
        if (snapshot.hasData) {
          List leads = snapshot.data;
          return dataList(leads);
        } else if (snapshot.error) {
          // print(snapshot.error);
          return Text("You have no clients");
        }

        return CircularProgressIndicator(
          backgroundColor: Colors.redAccent,
        );
      },
    );
  }

  Expanded dataList(List<MyClient> data) {
    return Expanded(
      child: ListView.builder(
          itemCount: data.length,
          primary: false,
          shrinkWrap: true,
          itemBuilder: (context, index) {
            final MyClient client = data[index];
            return LeadComponent(client);
          }),
    );
  }
}

我认为这里有问题,但是我对此不了解。 MyClient模型

import 'dart:convert';
import 'package:PandeetApp/services/myclient.dart';

class MyClient extends MyClientService {
  final int id, clientId, acceptedBy, pincode;
  final double latitude, longitude;
  final String perpose,
      details,
      when,
      name,
      mobile,
      email,
      orgName,
      address,
      city,
      state,
      country,
      clientIp,
      device,
      createdAt,
      updatedAt;

  MyClient({
    this.id,
    this.clientId,
    this.perpose,
    this.details,
    this.when,
    this.acceptedBy,
    this.name,
    this.mobile,
    this.email,
    this.orgName,
    this.address,
    this.city,
    this.state,
    this.country,
    this.latitude,
    this.longitude,
    this.pincode,
    this.clientIp,
    this.device,
    this.createdAt,
    this.updatedAt,
  });

  factory MyClient.fromJson(Map<String, dynamic> json) {
    return MyClient(
      id: json['id'],
      clientId: json['client_id'],
      perpose: json['perpose'],
      details: json['details'],
      when: json['when'],
      acceptedBy: json['accepted_by'],
      name: json['name'],
      mobile: json['mobile'],
      email: json['email'],
      orgName: json['org_name'],
      address: json['address'],
      city: json['city'],
      state: json['state'],
      pincode: json['pincode'],
      country: json['country'],
      latitude: json['latitude'],
      longitude: json['longitude'],
      clientIp: json['client_ip'],
      device: json['device'],
      createdAt: json['created_at'],
      updatedAt: json['updated_at'],
    );
  }

  Future<List<MyClient>> fetchClients() async {
    var datas = await super.fetchDatas();
    List dataList = jsonDecode(datas);

    return dataList.map((e) => MyClient.fromJson(e)).toList();
  }
}


这是我链接到API部分的API服务部分。可能需要了解代码。

MyClient服务

import 'package:http/http.dart' as http;
import 'package:PandeetApp/config/app.dart' as app;

class MyClientService {
  Future fetchDatas() async {
    var panditId = 1;
    var url = app.myclientsUrl + '?pid=$panditId';
    var response = await http.get(url);
    if (response.statusCode == 200) {
      var data = response.body;
      return data;
    } else {
      throw Exception('Failed to load jobs from API');
    }
  }
}

谢谢大家。

1 个答案:

答案 0 :(得分:1)

代替此:

if (snapshot.hasData) {
          List leads = snapshot.data;
          return dataList(leads);
        } else if (snapshot.error) {
          // print(snapshot.error);
          return Text("You have no clients");
        }

应该是这样:

if (snapshot.hasData) {
          List leads = snapshot.data;
          return dataList(leads);
        } else if (snapshot.hasError) {
          // print(snapshot.error);
          return Text("You have no clients");
        }

也可以这样:

Expanded dataList(List<MyClient> data) {
    return Expanded(
      child: ListView.builder(
          itemCount: data.length,
          primary: false,
          shrinkWrap: true,
          itemBuilder: (context, index) {
            final MyClient client = data[index];
            return LeadComponent(client);
          }),
    );
  }

您必须给ListViewBuilder固定高度:

Container dataList(List<MyClient> data) {
    return Container(
      height: 350,
      child: ListView.builder(
          itemCount: data.length,
          primary: false,
          shrinkWrap: true,
          itemBuilder: (context, index) {
            final MyClient client = data[index];
            return LeadComponent(client);
          }),
    );
  }

否则,它将溢出并且不显示任何内容。