Help needed for call_log package error "RangeError (index): Invalid value: Not in range 0..6, inclusive: -2"

2,260 views
Skip to first unread message

Nirav T

unread,
Jun 18, 2019, 5:11:33 PM6/18/19
to flutt...@googlegroups.com, n nirav
Please help to solve this problem.
Code for reference:
Iterable<CallLogEntry> _callLogEntries = [];
 
  @override
  Widget build(BuildContext context) {
    var mono = TextStyle(fontFamily: 'monospace');
    var children = <Widget>[];
    _callLogEntries.forEach((entry){
      children.add(
        Column(
          children: <Widget>[
            Divider(),
            Text('NUMBER : ${entry.formattedNumber}', style: mono),
            Text('NAME  : ${entry.name}', style: mono),
          ],
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
        ),
      );
    });
    return MaterialApp(
      home:Scaffold(
        appBar: AppBar(title: Text("Call List"),),
        body: SingleChildScrollView(
          child: Column(
            children: <Widget>[
              Center(
                child: Padding(
                    padding: const EdgeInsets.all(1.0),
                    child: RaisedButton(
                        onPressed: () async {
                          var result = await CallLog.query();
                          setState(() {
                            _callLogEntries = result;
                          });
                        },
                      child: Text("Get All"),
                    ),
                ),
              ),
              Padding(
                padding: const EdgeInsets.all(1.0),
                child: Column(children: children),
              ),
            ],
          ),
        ),
      ),
    );
  }


photo_2019-06-19_02-39-35.jpg

I/flutter (32680): RangeError (index): Invalid value: Not in range 0..6, inclusive: -2
I/flutter (32680):
I/flutter (32680): When the exception was thrown, this was the stack:
I/flutter (32680): #0      List.[] (dart:core-patch/array.dart:161:52)
I/flutter (32680): #1      new CallLogEntry.fromMap (package:call_log/call_log.dart:67:31)
I/flutter (32680): #2      CallLog.query.<anonymous closure> (package:call_log/call_log.dart:41:45)
I/flutter (32680): #3      MappedListIterable.elementAt (dart:_internal/iterable.dart:414:29)
I/flutter (32680): #4      ListIterable.forEach (dart:_internal/iterable.dart:39:14)
I/flutter (32680): #5      _TabCallsState.build (package:flutter_bottom_app/tab_call_log.dart:22:21)
I/flutter (32680): #6      StatefulElement.build (package:flutter/src/widgets/framework.dart:3825:27)
I/flutter (32680): #7      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3739:15)
I/flutter (32680): #8      Element.rebuild (package:flutter/src/widgets/framework.dart:3565:5)
I/flutter (32680): #9      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2278:33)
I/flutter (32680): #10     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:700:20)
I/flutter (32680): #11     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:286:5)
I/flutter (32680): #12     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1012:15)
I/flutter (32680): #13     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:952:9)
I/flutter (32680): #14     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:864:5)
I/flutter (32680): #18     _invoke (dart:ui/hooks.dart:219:10)
I/flutter (32680): #19     _drawFrame (dart:ui/hooks.dart:178:3)
I/flutter (32680): (elided 3 frames from package dart:async)
I/flutter (32680): ════════════════════════════════════════════════════════════════════════════════════════════════════

Ramón Estay

unread,
Jun 18, 2019, 5:35:51 PM6/18/19
to Flutter Development (flutter-dev)
hello... try this


child: Padding(
                    padding: const EdgeInsets.all(1.0),
                    child: RaisedButton(
                        onPressed: () async {
                          var result = await CallLog.query();
                          setState(() {
                            _callLogEntries = result;
                          });
                        },
                      child: Text("Get All"),
                    ),
                ),
              ),
  _callLogEntries.isEmpty 
  ? Container()
  : createPadding(),
  
..........


Widget createPadding(){
    var children = <Widget>[];
    _callLogEntries.forEach((entry){
      children.add(
        Column(
          children: <Widget>[
            Divider(),
            Text('NUMBER : ${entry.formattedNumber}', style: mono),
            Text('NAME  : ${entry.name}', style: mono),
          ],
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
        ),
      );
    });
return Padding(
                padding: const EdgeInsets.all(1.0),
                child: Column(children: children),
              );
}

Nirav T

unread,
Jun 18, 2019, 5:47:59 PM6/18/19
to Ramón Estay, flutt...@googlegroups.com
Thank you for your help but same error.

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/5f556701-67ee-40a7-a40e-2d908b198bc6%40googlegroups.com.

Ramón Estay

unread,
Jun 18, 2019, 8:21:02 PM6/18/19
to Flutter Development (flutter-dev)
I did this and works


import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);

final String title;

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

class _MyHomePageState extends State<MyHomePage> {
Iterable<CallLogEntry> _callLogEntries = [];
class CallLogEntry{
int formattedNumber;
String name;

CallLogEntry({this.formattedNumber, this.name});
}

class CallLog{
static Future<Iterable<CallLogEntry>> query() async {
var call1 = CallLogEntry(formattedNumber:1, name:'Name 1');
var call2 = CallLogEntry(formattedNumber:2, name:'Name 2');
Iterable<CallLogEntry> _callLogEntries = [call1, call2];
await Future.delayed(Duration(seconds: 1));
return _callLogEntries;
}
}
To unsubscribe from this group and stop receiving emails from it, send an email to flutt...@googlegroups.com.

Ramón Estay

unread,
Jun 18, 2019, 8:23:02 PM6/18/19
to Flutter Development (flutter-dev)
Maybe the problem is the service response. you could print the service response.

Nirav T

unread,
Jun 18, 2019, 11:35:54 PM6/18/19
to Ramón Estay, Flutter Development (flutter-dev)
Thank you for your great help.
I tried but It gives below result not call logs.
photo_2019-06-19_09-04-52.jpg

To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/266d3d1c-58a0-4a75-9f79-2c667ac9ca17%40googlegroups.com.

Ramón Estay

unread,
Jun 18, 2019, 11:40:59 PM6/18/19
to Flutter Development (flutter-dev)
could you print the query result?

Nirav T

unread,
Jun 19, 2019, 4:55:03 AM6/19/19
to Flutter Development (flutter-dev)


On Wednesday, June 19, 2019 at 9:10:59 AM UTC+5:30, Ramón Estay wrote:
could you print the query result?

Reply all
Reply to author
Forward
0 new messages