Finished with error: RangeError (index): Invalid value: Only valid value is 0: 1

6,468 views
Skip to first unread message

hatted bey

unread,
Jul 1, 2018, 3:53:11 AM7/1/18
to Flutter Dev
I started learning the flutter and copy and paste the code from

but i got an error below:
Launching lib/main.dart on iPhone X in debug mode...
Finished with error: RangeError (index): Invalid value: Only valid value is 0: 1

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  final appTitle = 'Drawer Demo';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: appTitle,
      home: MyHomePage(title: appTitle),
    );
  }
}

class MyHomePage extends StatelessWidget {
  final String title;

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(title)),
      body: Center(child: Text('My Page!')),
      drawer: Drawer(
        // Add a ListView to the drawer. This ensures the user can scroll
        // through the options in the Drawer if there isn't enough vertical
        // space to fit everything.
        child: ListView(
          // Important: Remove any padding from the ListView.
          padding: EdgeInsets.zero,
          children: <Widget>[
            DrawerHeader(
              child: Text('Drawer Header'),
              decoration: BoxDecoration(
                color: Colors.blue,
              ),
            ),
            ListTile(
              title: Text('Item 1'),
              onTap: () {
                // Update the state of the app
                // ...
                // Then close the drawer
                Navigator.pop(context);
              },
            ),
            ListTile(
              title: Text('Item 2'),
              onTap: () {
                // Update the state of the app
                // ...
                // Then close the drawer
                Navigator.pop(context);
              },
            ),
          ],
        ),
      ),
    );
  }
}

Marc Endtricht

unread,
Jul 1, 2018, 5:09:53 AM7/1/18
to Flutter Dev
Works without a problem on my side, as far as i can tell, the code should be fine...

hatted bey

unread,
Jul 1, 2018, 9:41:55 AM7/1/18
to Flutter Dev
Thanks.  I just found it is cached in the flutter.

You can run flutter clean.
Or you can delete the /build folder under your /project folder if you cannot run flutter command.

Danny Tuppeny

unread,
Jul 1, 2018, 4:56:32 PM7/1/18
to Flutter Dev
Here's the related GH issue - it's fixed in master, but hasn't made the beta channel yet:

khaliq Dad

unread,
Apr 30, 2020, 8:40:23 AM4/30/20
to Flutter Development (flutter-dev)
try this it will help you:

On Sunday, July 1, 2018 at 3:53:11 PM UTC+8, hatted bey wrote:
Reply all
Reply to author
Forward
0 new messages