skip to Main Content

I am tryiong to display a list of events a user has registered for in a flutter app but i keep getting this error even though I am following the tuorial closely. I believe the error might be in the following lines but I have checked multiple times but havent gotten a fix.

        ref.watch(userEventsProvider).when(
              data: (events) => Expanded(
                child: ListView.builder(
                  itemCount: events.length,
                  itemBuilder: (BuildContext context, int index) {
                    final event = events[index];
                    return ListTile(
                      leading: CircleAvatar(
                        backgroundImage: NetworkImage(event.images),
                      ),
                      title: Text('/r${event.name}'),
                      onTap: () {},
                    );
                  },
                ),
              ),
              error: (error, stackTrace) => ErrorText(
                error: error.toString(),
              ),
              loading: () => const Loader(),
            ),

I have tried following the tutorial but theres seems to be no fix.

2

Answers


  1. it seems like the issue might be with the event.images field. it’s actually a list of dynamic objects.

    CircleAvatar(
      backgroundImage: NetworkImage(event.images[index]), // Corrected line
    ),
    

    Replace index with the appropriate index

    Login or Signup to reply.
  2. ref.watch(userEventsProvider).when(
                  data: (events) => Expanded(
                    child: ListView.builder(
                      itemCount: events.length,
                      itemBuilder: (BuildContext context, int index) {
                        
                        return ListTile(
                          leading: CircleAvatar(
                            backgroundImage: NetworkImage(events[index].images),
                          ),
                          title: Text('/r${events[index].name}'),
                          onTap: () {},
                        );
                      },
                    ),
                  ),
                  error: (error, stackTrace) => ErrorText(
                    error: error.toString(),
                  ),
                  loading: () => const Loader(),
                ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search