Micah Githens
Micah Githens

Reputation: 1261

Flutter/Dart Error: Unexpected tag 0 (Nothing) in [email protected]

I've run into the following error while trying to follow this tutorial. Oddly, Googling this error message did not resulted in any helpful insight.

Error Message:

I/flutter ( 5472): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY 
╞═══════════════════════════════════════════════════════════
I/flutter ( 5472): The following _CompileTimeError was thrown building MyApp(dirty, state: _MyAppState#f8841):
I/flutter ( 5472): 'file:///Users/micah/MobileApps/flutter_test_1/lib/main.dart': error: Unexpected tag 0 (Nothing) in
I/flutter ( 5472): [email protected], expected a procedure, a constructor or a function node
I/flutter ( 5472):
I/flutter ( 5472): When the exception was thrown, this was the stack:
I/flutter ( 5472): #0      StatefulElement.build (package:flutter/src/widgets/framework.dart:3730:27)

main.dart file:

import 'package:flutter/material.dart';

//    import './product_manager.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
      //  appBar: AppBar(
      //    title: Text('EasyList'),
      //  ),
      //  body: ProductManager(),
      ),
    );
  }
}

products.dart file:

import 'package:flutter/material.dart';

class Products extends StatelessWidget {
  final List<String> products;

  Products(this.products);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: products
        .map(
          (element) => Card(
                child: Column(
                  children: <Widget>[
                    Image.asset('assets/food.jpg'),
                    Text(element)
                  ],
                ),
              ),
        )
        .toList()
      );
  }
}

product_manager.dart file:

import 'package:flutter/material.dart';

import './products.dart';

class ProductManager extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _ProductManagerState();
  }
}

class _ProductManagerState extends State<ProductManager> {
  List<String> _products = ['Food Tester'];

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Container(
          margin: EdgeInsets.all(10.0),
          child: RaisedButton(
            onPressed: () {
              setState(() {
                _products.add('Advanced Food Tester');
              });
            },
            child: Text('Add Product'),
          ),
        ),
        Products(_products)
      ],
    );
  }
}

Upvotes: 1

Views: 1355

Answers (1)

Micah Githens
Micah Githens

Reputation: 1261

Clicking the "Restart Debugging" fixed the issues.

I believe the problem may be related to the fact that I changed from a StatefullWidget to a StatelessWidget without restarting the debugger.

Upvotes: 6

Related Questions