首页 > 解决方案 > 错误:“int”类型不是“Map”类型的子类型'在颤抖中

问题描述

从firebase数据库查看数据有什么问题错误:类型'int'不是'Map <dynamic,dynamic>'类型的子类型............ ..................................................... .. 在此处输入图像描述 .................................... .........................................

在此处输入图像描述 ................................... .....................

class LeaderBoard extends StatefulWidget {
  @override
  _LeaderBoardState createState() => _LeaderBoardState();
}

class _LeaderBoardState extends State<LeaderBoard> {
  Query _ref;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _ref = FirebaseDatabase.instance.reference().child('Score')
    .orderByChild('scoreVaule')
    .limitToFirst(200);
   
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          Container(
            height: displayHeight(context) * 0.15,
          ),
          Container(
            height: displayWidth(context) * 0.25,
            width: displayWidth(context) * 0.25,
            child: Image.asset('assets/images/icon.png', fit: BoxFit.fill),
          ),
          SizedBox(
            height: 10,
          ),
          Container(
            color: Colors.blue,
            height: displayHeight(context) * 0.06,
            width: displayWidth(context),
            child: Center(
              child: Text(
                'الأوائل',
                style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
                textAlign: TextAlign.center,
              ),
            ),
          ),
          ///////////
          SizedBox(
            height: 5,
          ),
          Container(
            //color: Colors.red,
            width: displayWidth(context) * 0.60,
            height: 350,
            child: new FirebaseAnimatedList(
              query: _ref,
              itemBuilder: (
                BuildContext context,
                DataSnapshot snapshot,
                Animation<double> animation,
                int index,
              ) {
                String mountainKey = snapshot.key;
                Map map = snapshot.value;
                String _name = map['name'] as String;
                int _score = map['scoreVaule'] as int;
                //int _time = map['time'] as int;
                String _image1 = map['profileImageurl'] as String;
                if (_image1 == null) {
                  _image1 =
                      'https://firebasestorage.googleapis.com/v0/b/hroof-74034.appspot.com/o/users%2Ficon.png?alt=media&token=b7e1b4f4-57a4-4aaa-9ebc-d0dfd3eb4719';
                }
                return new Column(
                  children: <Widget>[
                    new ListTile(
                      title: new Text('$_name'),
                      subtitle: new Text('$_score'),
                      /*leading: new Container(
                              width: 40.0,
                              height: 40.0,
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.only(
                                  topRight: Radius.circular(40.0),
                                  bottomRight: Radius.circular(40.0),
                                  bottomLeft: Radius.circular(40.0),
                                  topLeft: Radius.circular(40.0),
                                ),
                                //color: Colors.black,
                                image: DecorationImage(
                                  image: NetworkImage(_image1),
                                  fit: BoxFit.fill,
                                ),
                              ),
                            ),*/
                    ),
                    new Divider(
                      height: 2.0,
                    ),
                  ],
                );
              },
                sort: (a, b) {
               return b.value['scoreVaule']
                .toString()
                .compareTo(a.value['scoreVaule'].toString());
              },
            ),
          ),

          ///////////
        ],
      ),
    );
  }
}

快照.value

VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: Class 'int' has no instance method '[]'.
Receiver: -27
Tried calling: []("scoreVaule")
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1      _LeaderBoardState.build.<anonymous closure>
package:khlea/leaderBoard.dart:111
#2      Sort._insertionSort (dart:_internal/sort.dart:69:36)
#3      Sort._doSort (dart:_internal/sort.dart:58:7)
#4      Sort.sort (dart:_internal/sort.dart:33:5)
#5      ListMixin.sort (dart:collection/list.dart:355:10)
#6      FirebaseSortedList._onChildAdded
package:firebase_database/ui/firebase_sorted_list.dart:89
#7      _rootRunUnary (dart:async/zone.dart:1198:47)
#8      _CustomZone.runUnary (dart:async/zone.dart:1100:19)
#9      _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
#10     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
#11     _DelayedData.perform (dart:async/stream_impl.dart:611:14)
#12     _StreamImplEvents.handleNext (<…&gt;

标签: flutterdart

解决方案


推荐阅读