升级后的颤振后颤振选项卡栏错误“在null上调用了getter'key'

时间:2019-11-03 02:32:43

标签: flutter dart flutter-layout flutter-dependencies

  

以下NoSuchMethodError被抛出   MediaQuery(MediaQueryData(size:Size(360.0,640.0),devicePixelRatio:   3.0,textScaleFactor:1.0,platformBrightness:Brightness.light,padding:EdgeInsets.zero,viewPadding:EdgeInsets.zero,viewInsets:   EdgeInsets.zero,物理深度:1.7976931348623157157e + 308,   alwaysUse24HourFormat:false,可访问Navigation:false,   disableAnimations:false,invertColors:false,boldText:false)):   getter'key'在null上被调用。接收方:空尝试呼叫:键

     

由用户创建的导致错误的小部件的祖先是:脚手架   文件:///home/midhilajm/Downloads/al-qasier-flutter-solving_issue_20/lib/orderDetails/OrderDetails.dart:27:16   引发异常时,这是堆栈:

     

0 Object.noSuchMethod(dart:core-patch / object_patch.dart:51:5)

     

1个新的KeyedSubtree.wrap(软件包:flutter / src / widgets / basic.dart:6605:27)

     

2 KeyedSubtree.ensureUniqueKeysForList(package:flutter / src / widgets / basic.dart:6623:44)

     

3 _TabBarViewState._updateChildren(package:flutter / src / material / tabs.dart:1237:37)

     

4 _TabBarViewState.initState(package:flutter / src / material / tabs.dart:1206:5)...

     

═══════════════════════════════════════════════ ══════════════════════════════════════════════════ ═══

import'package:alqaiser / cart / MyCart.dart';     导入'package:alqaiser / orderHistory / OrderHistoryModule.dart';     导入'package:alqaiser / orderHistory / OrderItem.dart';     导入'package:alqaiser / toolbar / MyToolBar.dart';     导入'package:alqaiser / utlity / Milla.dart';     导入'package:flutter / material.dart';

class OrderDetails extends StatefulWidget {
  OrderItem order;
  OrderDetails({this.order}) {}
  @override
  _OrderDetailsState createState() => _OrderDetailsState(order: order);
}

class _OrderDetailsState extends State<OrderDetails> {
  OrderItem order;
  _OrderDetailsState({this.order}) {

  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MyToolBar().getAppBar(context),
      body: DefaultTabController(
        length: 2,
        child: Scaffold(
          appBar: AppBar(
            title: TabBar(
              tabs: [
                Tab(
                  text: "Work followup",
                ),
                Tab(
                  text: "Payment ",
                ),
              ],
            ),
          ),
          body: TabBarView(children: [getWorkStatus(), getPaymentStatus()]),
        ),
      ),
    );
  }

  Widget getPaymentStatus() {
    if (this.order.paymentS != null)
      return ListView.builder(
          itemCount: this.order.paymentS.length,
          itemBuilder: (BuildContext context, int index) {
            return Bubble(message: this.order.paymentS[index]);
          });
  }

  Widget getWorkStatus() {
    if (this.order.statues != null)
      return ListView.builder(
          itemCount: this.order.statues.length,
          itemBuilder: (BuildContext context, int index) {
            return Bubble(message: this.order.statues[index]);
          });
  }
}

class Bubble extends StatelessWidget {
  Color bg =Colors.blueGrey ;
  String message1="",message2="";
  Bubble(
      {this.message,
      this.time = "12",
      this.delivered = false,
      this.isMe = false});

  final String message, time;
  final delivered, isMe;
  List<String> messageSplit = [];
  @override
  Widget build(BuildContext context) {
    messageSplit = message.split(":");
    if(messageSplit.length>=1?messageSplit[0]!=null?true:false:false)
  message1=messageSplit[0];
    if(messageSplit.length>=3?
  messageSplit[2]!=null?true:false:false)
    message2=messageSplit[2];
    if(messageSplit.length>=2?
    messageSplit[1]!=null?true:false:false)
    bg=isMe ? Colors.white :HexColor(messageSplit[1]);
    final align = isMe ? CrossAxisAlignment.start : CrossAxisAlignment.end;
    final icon = delivered ? Icons.done_all : Icons.done;
    final radius = isMe
        ? BorderRadius.only(
            topRight: Radius.circular(5.0),
            bottomLeft: Radius.circular(10.0),
            bottomRight: Radius.circular(5.0),
          )
        : BorderRadius.only(
            topLeft: Radius.circular(5.0),
            bottomLeft: Radius.circular(5.0),
            bottomRight: Radius.circular(10.0),
          );
    return Column(
      crossAxisAlignment: align,
      children: <Widget>[
        Container(
          margin: const EdgeInsets.all(3.0),
          padding: const EdgeInsets.all(8.0),
          decoration: BoxDecoration(
            boxShadow: [
              BoxShadow(
                  blurRadius: .5,
                  spreadRadius: 1.0,
                  color: Colors.black.withOpacity(.12))
            ],
            color: bg,
            borderRadius: radius,
          ),
          child:Column(
            children: <Widget>[
              Container(

              child:    Text(message1,textAlign: TextAlign.right,style: TextStyle(color: Colors.white),),
          )
          ,
              Text(message2,textAlign: TextAlign.right,
                  style: TextStyle(
                    color: Colors.white70,
                    fontSize: 10.0,
                  )),
            ],
          ),
        )
      ],
    );
  }
}

1 个答案:

答案 0 :(得分:0)

您不能有可能不返回任何值的方法。付款==空时会返回什么?

Widget getPaymentStatus() {
if (this.order.paymentS != null)
  return ListView.builder(
      itemCount: this.order.paymentS.length,
      itemBuilder: (BuildContext context, int index) {
        return Bubble(message: this.order.paymentS[index]);
      });
}

您应该处理所有情况,例如:

Widget getPaymentStatus() {
 if (this.order.paymentS != null){
   return ListView.builder(
      itemCount: this.order.paymentS.length,
      itemBuilder: (BuildContext context, int index) {
        return Bubble(message: this.order.paymentS[index]);
      });
 }
 else{
  return Container()
 }
}