Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Exception caught by widgets library: The following assertion was thrown building _ContactItem(dirty): setState() or markNeedsBuild() called during build. Começa a dar erro quando adiciono a navegação para o transactionform

import 'package:flutter/material.dart';
import 'package:flutter2/components/progress.dart';
import 'package:flutter2/database/app_database.dart';
import 'package:flutter2/models/contact.dart';
import 'package:flutter2/screens/transaction_form.dart';

import 'contact_form.dart';

class ContactList extends StatefulWidget {
  @override
  _ContactListState createState() => _ContactListState();
}

class _ContactListState extends State<ContactList> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Transfer'),
      ),
      body: FutureBuilder<List<Contact>>(
        initialData: List(),
        future: findAll(),
        builder: (context, snapshot) {
          switch (snapshot.connectionState) {
            case ConnectionState.none:
              // TODO: Handle this case.
              break;
            case ConnectionState.waiting:
              return Progress(
                message: 'Loading Contacts',
              );
              break;
            case ConnectionState.active:
              break;
            case ConnectionState.done:
              final List<Contact> contacts = snapshot.data;
              return ListView.builder(
                itemBuilder: (context, index) {
                  final contact = contacts[index];
                  return _ContactItem(
                    contact,
                    onClick: () {
                      Navigator.of(context).push(
                        MaterialPageRoute(
                          builder: (context) => TransactionForm(contact),
                        ),
                      );
                    },
                  );
                },
                itemCount: contacts.length,
              );
              break;
          }
          return Text('unknown error!');
        },
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          Navigator.of(context).push(
            MaterialPageRoute(
              builder: (context) => ContactForm(),
            ),
          );
        },
        child: Icon(
          Icons.add,
        ),
      ),
    );
  }
}

class _ContactItem extends StatelessWidget {
  final Contact contact;
  final Function onClick;

  _ContactItem(this.contact, {@required this.onClick});

  @override
  Widget build(BuildContext context) {
    return Card(
        child: ListTile(
            onTap: onClick(),
            title: Text(
              contact.name,
              style: TextStyle(fontSize: 24.0),
            ),
            subtitle: Text(contact.accountNumber.toString(),
                style: TextStyle(fontSize: 16.0))));
  }
}
2 respostas
solução!

substitua o seu onTap: onClick() por onTap: onClick

verifiquei aqui: https://stackoverflow.com/questions/56329987/nosuchmethoderror-the-method-drive-was-called-on-null

Valeu Rayner! Funcionou