'geting data from firebase in flutter

im trying to get data from firebase

the main page show the data correctly based on the length but the details page is not the data of the first index is duplicated to the on the other pages

this is the main page and it shows different data correctly

but the first details page keep duplicate it self

this is the detail page code

import 'package:carousel_slider/carousel_slider.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:online_shop/api/summer_list_api.dart';
import 'package:online_shop/core/services/summer_notifier.dart';
import 'package:online_shop/model/Summer_d_model.dart';
import 'package:online_shop/pages/home_page.dart';
import 'package:online_shop/view/widgets/costum_button.dart';
import 'package:online_shop/view/widgets/costum_text.dart';
import 'package:online_shop/view/widgets/nav.dart';
import 'package:provider/provider.dart';

class DetalsPage extends StatefulWidget {
  DetalsPage({Key? key}) : super(key: key);

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

class _DetalsPage extends State<DetalsPage> {
  late Future Summers;

  @override
  void initState() {
    Summers = getsummerinfo(SummerNotifier());
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    SummerNotifier summerNotifier = Provider.of<SummerNotifier>(context);

    return Scaffold(
      body: ListView.builder(
        itemCount: 1,
        scrollDirection: Axis.vertical,
        itemBuilder: (context, index) {
          return Column(
            children: [
              Container(
                child: Stack(
                  children: [
                    Image.network(
                      summerNotifier.summerList[index].Imag,
                      width: 400,
                      fit: BoxFit.fitWidth,
                    ),
                    Container(
                        margin: const EdgeInsets.only(top: 40, left: 5),
                        child: IconButton(
                            onPressed: () {
                              Navigator.push(context,
                                  MaterialPageRoute(builder: (context) {
                                return Nav();
                              }));
                            },
                            icon: Icon(Icons.arrow_back_ios))),
                    Container(
                      height: 575,
                      margin: const EdgeInsets.only(top: 230),
                      decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.circular(20)),
                      child: Padding(
                        padding: const EdgeInsets.only(top: 5, bottom: 5),
                        child: ListView.builder(
                          itemCount: 1,
                          scrollDirection: Axis.vertical,
                          itemBuilder: (context, index) {
                            return Column(
                              children: [
                                Padding(
                                  padding: const EdgeInsets.only(
                                    left: 10,
                                  ),
                                  child: CoustumText(
                                    text: summerNotifier.summerList[index].name,
                                    size: 30,
                                    color: Colors.black,
                                    fontWeight: FontWeight.bold,
                                  ),
                                ),
                                const SizedBox(
                                  height: 10,
                                ),
                                Padding(
                                  padding: const EdgeInsets.only(
                                      left: 10, right: 10),
                                  child: CoustumText(
                                    text: summerNotifier
                                        .summerList[index].sub_info,
                                    size: 16,
                                    color: Colors.black,
                                  ),
                                ),
                                const SizedBox(height: 20),
                                Padding(
                                  padding: const EdgeInsets.only(left: 10),
                                  child: CoustumText(
                                    text: "some of the place photos:",
                                    size: 18,
                                    color: Colors.black,
                                    fontWeight: FontWeight.w600,
                                  ),
                                ),
                                const SizedBox(
                                  height: 10,
                                ),
                                FutureBuilder(
                                    future: Summers,
                                    builder: (context, snapshot) {
                                      switch (snapshot.connectionState) {
                                        case ConnectionState.none:
                                          return Text("there is issu ");
                                        case ConnectionState.waiting:
                                          return CircularProgressIndicator();

                                        default:
                                          if (snapshot.hasError) {
                                            return Text("Error");
                                          }
                                      }
                                      return CarouselSlider(
                                        items: summerNotifier
                                            .summerList[index].sub_img
                                            ?.map((items) => Container(
                                                  height: 200,
                                                  child: Image.network(
                                                    items,
                                                    fit: BoxFit.cover,
                                                  ),
                                                ))
                                            .toList(),
                                        options:
                                            CarouselOptions(autoPlay: false),
                                      );
                                    }),
                                const SizedBox(
                                  height: 20,
                                ),
                                Padding(
                                  padding: const EdgeInsets.only(left: 10),
                                  child: CoustumText(
                                    text: "trip informations:",
                                    size: 20,
                                    color: Colors.black,
                                    fontWeight: FontWeight.w600,
                                  ),
                                ),
                                const SizedBox(
                                  height: 10,
                                ),
                                Padding(
                                  padding: const EdgeInsets.only(
                                      left: 10, right: 10),
                                  child: Container(
                                    child: CoustumText(
                                      text:
                                          "The trip is for 7 days and 8 nights and ther will be a program for spinding the time,every day ther will be a new place to discover so relax and lets the journy start.",
                                      size: 16,
                                      color: Colors.black,
                                    ),
                                  ),
                                ),
                                const SizedBox(
                                  height: 20,
                                ),
                                Container(
                                  child: Padding(
                                    padding: const EdgeInsets.only(
                                        left: 10, right: 10),
                                    child: Column(
                                      children: [
                                        CoustumText(
                                          text: "Contact informations:",
                                          size: 20,
                                          color: Colors.black,
                                          fontWeight: FontWeight.w600,
                                        ),
                                        SizedBox(
                                          height: 10,
                                        ),
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceBetween,
                                          children: [
                                            Row(
                                              children: const [
                                                Icon(
                                                  Icons.phone,
                                                  size: 20,
                                                ),
                                                SizedBox(
                                                  width: 5,
                                                ),
                                                CoustumText(
                                                    text: "85746385",
                                                    size: 16,
                                                    color: Colors.black),
                                              ],
                                            ),
                                            Row(
                                              children: const [
                                                Icon(
                                                  Icons.facebook_rounded,
                                                  color: Colors.blueAccent,
                                                  size: 30,
                                                ),
                                                SizedBox(
                                                  width: 5,
                                                ),
                                                CoustumText(
                                                    text: "Flay_fun",
                                                    size: 16,
                                                    color: Colors.black),
                                              ],
                                            ),
                                          ],
                                        ),
                                        const SizedBox(
                                          height: 5,
                                        ),
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceBetween,
                                          children: [
                                            Row(
                                              children: const [
                                                Icon(
                                                  Icons.phone,
                                                  size: 20,
                                                ),
                                                SizedBox(
                                                  width: 5,
                                                ),
                                                CoustumText(
                                                    text: "85208579",
                                                    size: 16,
                                                    color: Colors.black),
                                              ],
                                            ),
                                            Row(
                                              children: const [
                                                Icon(
                                                  Icons.email_rounded,
                                                  color: Colors.blueAccent,
                                                  size: 30,
                                                ),
                                                SizedBox(
                                                  width: 5,
                                                ),
                                                CoustumText(
                                                    text: "[email protected]",
                                                    size: 16,
                                                    color: Colors.black),
                                              ],
                                            ),
                                          ],
                                        ),
                                      ],
                                    ),
                                  ),
                                ),
                                const SizedBox(
                                  height: 20,
                                ),
                                Container(
                                  width: 200,
                                  child: CoustumButton(
                                    text: "book now \$200",
                                    onPressed: () {},
                                    size: 20,
                                  ),
                                ),
                              ],
                            );
                          },
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ],
          );
        },
      ),
    );
  }
}

this is the method to get the data

// ignore_for_file: unused_local_variable, non_constant_identifier_names

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:online_shop/core/services/summer_notifier.dart';
import 'package:online_shop/model/Summer_d_model.dart';


Future  getsummerinfo  (SummerNotifier summerNotifier) async {
  QuerySnapshot snapshot =
      await FirebaseFirestore.instance.collection("Summer_D").get();

  List<Summer_d> _summerList = [];

  snapshot.docs.forEach((docs) {
    Summer_d summer_d = Summer_d.fromMap(docs.data() as Map<String, dynamic>);
    _summerList.add(summer_d);
  });
  summerNotifier.summerList = _summerList;

  
}

this is the other one

// ignore_for_file: unused_local_variable, non_constant_identifier_names

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:online_shop/core/services/summer_notifier.dart';
import 'package:online_shop/model/Summer_d_model.dart';


Future  getsummerinfo  (SummerNotifier summerNotifier) async {
  QuerySnapshot snapshot =
      await FirebaseFirestore.instance.collection("Summer_D").get();

  List<Summer_d> _summerList = [];

  snapshot.docs.forEach((docs) {
    Summer_d summer_d = Summer_d.fromMap(docs.data() as Map<String, dynamic>);
    _summerList.add(summer_d);
  });
  summerNotifier.summerList = _summerList;

  
}

this is the models

// ignore_for_file: camel_case_types

 class Summer_d {
  late String Imag;
  late String info;
  late String name;
  late int price;
  late String sub_info;
  late List<dynamic>? sub_img;

 

  Summer_d.fromMap(Map<String,dynamic>data){
    Imag = data["Imag"];
    info = data ["info"];
    name = data ["name"];
    price = data["price"];
    sub_info = data ["sub_info"];
    sub_img = data ["sub_img"];

    
    

  }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source