Flutter, selecting int and double values via a selector wheel and Parsing them from one page to another

I’m trying to select a height (int) and weight (double) value on one page using a selector wheel widget and then sending it to another page to display and eventually use the values in calculations.

I tried parsing the variables via the constructors but they stay stuck at 0 or 0.0 no matter what. I’m not sure if the issue come from the selector wheel not saving my choice or the parsing setting the value to 0 at some point

Here are the different pages involved, they’re separated in multiple .dart files:

main.dart:

import 'package:appli_teeshirt/pages/profile.dart';
import 'package:appli_teeshirt/pages/bt_connect.dart';
import 'package:appli_teeshirt/pages/historique.dart';
import 'package:appli_teeshirt/pages/page_accueil.dart';
import 'package:flutter/material.dart';

final GlobalKey<_MyappState> myAppKey = GlobalKey<_MyappState>();

void main() {
  runApp(Myapp(key: myAppKey));
}

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

  @override
  State<Myapp> createState() => _MyappState();
}

class _MyappState extends State<Myapp> {
  int _currentIndex = 0;
  double _poids = 0.0;
  int _taille = 0;

  void setCurrentIndex(int index) {
    setState(() {
      _currentIndex = index;
    });
  }

  void setPoidsAndTaille(double poids, int taille) {
    setState(() {
      _poids = poids;
      _taille = taille;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: [
            const Text("Accueil"),
            const Text("Connection Bluetooth"),
            const Text("Historique des courses"),
            const Text("Profile Utilisateur"),
          ][_currentIndex],
        ),
        body: IndexedStack(
          index: _currentIndex,
          children: [
            const PageAccueil(),
            const BTconnect(),
            historique(poids: _poids, taille: _taille),
            UserProfile(
              onSubmit: (index) {
                setCurrentIndex(index);
              },
              onPoidsTailleChange: (poids, taille) {
                setPoidsAndTaille(poids, taille);
              },
            ),
          ],
        ),
        bottomNavigationBar: BottomNavigationBar(
          currentIndex: _currentIndex,
          onTap: setCurrentIndex,
          type: BottomNavigationBarType.fixed,
          selectedItemColor: Colors.deepPurple,
          unselectedItemColor: Colors.grey,
          iconSize: 32,
          elevation: 10,
          items: const [
            BottomNavigationBarItem(
                icon: Icon(Icons.home),
                label: 'Accueil'
            ),
            BottomNavigationBarItem(
                icon: Icon(Icons.bluetooth),
                label: 'Connection BT'
            ),
            BottomNavigationBarItem(
                icon: Icon(Icons.history),
                label: 'Historique'
            ),
            BottomNavigationBarItem(
                icon: Icon(Icons.account_circle),
                label: 'profile'
            )
          ],
        ),
      ),
    );
  }
}

profile.dart (where I select the values):

import 'package:flutter/material.dart';
import 'package:selector_wheel/selector_wheel.dart';
import 'package:appli_teeshirt/main.dart';

class UserProfile extends StatefulWidget {
  final void Function(int) onSubmit;
  final void Function(double, int) onPoidsTailleChange;

  const UserProfile({
    Key? key,
    required this.onSubmit,
    required this.onPoidsTailleChange,
  }) : super(key: key);

  @override
  State<UserProfile> createState() => _UserProfileState();
}



class _UserProfileState extends State<UserProfile> {

  final _formKey = GlobalKey<FormState>();

  final profilNameController = TextEditingController();
  final tailleController = TextEditingController();

  @override
  void dispose() {
    super.dispose();

    profilNameController.dispose();
    tailleController.dispose();
  }
  @override
  Widget build(BuildContext context) {
    double selectedPoids = 0.0;
    int selectedTaille = 0;
    return Container(
      margin: const EdgeInsets.all(20),
      child: Form(
        key: _formKey,
          child: Column(
            children: [
              Container(
                margin: const EdgeInsets.only(bottom: 10),
                child: TextFormField(
                  decoration: const InputDecoration(
                    labelText: "nom du profil",
                    hintText: "entre ton nom",
                    border: OutlineInputBorder(),
                  ),
                  validator: (value){
                    if (value == null || value.isEmpty){
                      return "Tu dois completer ce texte";
                    }
                    return null;
                  },
                ),
              ),

              Row(
                mainAxisSize: MainAxisSize.min,
              children: [
                Column(
                  children: [
              const Text('Poids'),
              SizedBox(
                width: 100,
                height: 200,
                child: SelectorWheel(
                  childCount: 241,
                  diameterRatio: 3.5,
                  convertIndexToValue: (int index) {
                    // This is just to illustrate, that the index can be converted
                    // to any value. In this case, we are converting the index to
                    // a quarter of a pound.
                    final quarter = (index +60) / 2;

                    return SelectorWheelValue(
                      // The label is what is displayed on the selector wheel
                      label: '${quarter.toString()} kg',
                      value: quarter,
                      index: index,
                    );
                  },
                  onValueChanged: (SelectorWheelValue<double> value) {
                    // print the value that was selected
                    setState(() {
                      selectedPoids = value.value;
                    });
                      },
                    ),
                  ),
                ],
              ),
                Column(
                  children: [
                    const Text('Taille'),
                    SizedBox(
                      width: 100,
                      height: 200,
                      child: SelectorWheel(
                        childCount: 121,
                        diameterRatio: 3.5,
                        convertIndexToValue: (int index) {
                          final height = index + 130;
                         // final quarter = (index +130) /1;

                          return SelectorWheelValue(
                            // The label is what is displayed on the selector wheel
                            label: '${height.toString()} cm',
                            value: height,
                            index: index,
                          );
                        },
                        onValueChanged: (SelectorWheelValue<int> value) {
                          // print the value that was selected
                          setState(() {
                            selectedTaille = value.value;
                          });
                        },
                      ),
                    ),
                  ],
                ),
              ],
              ),
              SizedBox(
                width: double.infinity,
                height: 50,
                child: ElevatedButton(
                  onPressed: () {
                    if (_formKey.currentState!.validate()) {
                      ScaffoldMessenger.of(context).showSnackBar(
                        const SnackBar(content: Text("envoi en cours...")),
                      );
                      FocusScope.of(context).requestFocus(FocusNode());

                      // Get the selected "Poids" and "Taille" values
                      double poids = selectedPoids;
                      int taille = selectedTaille;

                      // Call the onSubmit callback with the desired index
                      widget.onSubmit(3);
                    }
                  },
                  child: const Text("Envoyer"),
                ),


              ),
            ],
          )
      ),
    );
  }
}

historique.dart (where I want to display the values, specifically I want to display them in DetailsScreen

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class historique extends StatelessWidget {
  final double poids;
  final int taille;
  final List<Map<String, dynamic>> courses = [
    {
      "name": "Course 1",
      "date": "20/03/2024",
      //"logo": "course1",
      "distance": 12967,
      "temps": 7384
    },
    {
      "name": "Course 2",
      "date": "06/03/2024",
      // "logo": "course2",
      "distance": 17413,
      "temps": 13854
    },
    {
      "name": "Course 3",
      "date": "27/02/2024",
      //   "logo": "course3",
      "distance": 4967,
      "temps": 3891
    },
  ];

  historique({required this.poids, required this.taille, Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // Your build method remains the same
    return Scaffold(

        body: Column(
          children: [
            Expanded(
                child:
                ListView.builder(
                  itemCount: courses.length,
                  itemBuilder: (context, index) {
                    final course = courses[index];
                    final logo = course['logo'];
                    final name = course['name'];
                    final date = course['date'];

                    return InkWell(
                      onTap: () => Navigator.of(context).push(
                        MaterialPageRoute(
                            builder: (context) => DetailsScreen(
                              poids: poids,
                              taille: taille,

                            ),
                            settings: RouteSettings(
                                arguments: course
                            )
                        ),

                      ),
                      child: Card(
                        child: ListTile(
                          leading: Image.asset("assets/images/course2.png"),
                          title: Text(name),
                          subtitle: Text('course du $date'),
                          trailing: const Icon(Icons.more_vert),
                        ),
                      ),
                    );
                  },
                )
            ),
          ],
        )
    );
  }
}

class DetailsScreen extends StatelessWidget {

  final double poids;
  final int taille;

  const DetailsScreen({Key? key, required this.poids, required this.taille}) : super(key: key);

  @override
  Widget build(BuildContext context) {

    var course = ModalRoute.of(context)!.settings.arguments  as Map<String,dynamic>;

    int hours = course['temps'] ~/ 3600;
    int minutes = (course['temps'] ~/ 60) % 60;
    int seconds = course['temps'] % 60;


    return Scaffold(
      appBar: AppBar(
        title:
           Text("${course['name']}"),
      ),
      body: SafeArea(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,

          children: [
            UnconstrainedBox(

              child: Card(
                color: Colors.lightBlueAccent,
                  child:
                  Text(
                    " date : ${course['date']} ",
                    style: const TextStyle(
                        fontSize: 24,
                        //fontFamily: 'Poppins'
                    ),
                  ),
              ),
            ),
            const SizedBox(
              height: 15,
              width: 100,
            ),
            UnconstrainedBox(
              child: Card(
                color: Colors.lightBlueAccent,
                child:
                Text(
                  " distance : ${course['distance']}m n  temps : $hours:$minutes'$seconds ",
                  style: const TextStyle(
                      fontSize: 24,
                     //  fontFamily: 'Poppins'
                  ),
                ) ,
              ),
            ),
            const SizedBox(
              height: 15,
              width: 100,
            ),
            UnconstrainedBox(
              child: Card(
                color: Colors.lightBlueAccent,
                child:
                Text(
                  " taille : $taille n  temps : $poids ",
                  style: const TextStyle(
                    fontSize: 24,
                    //  fontFamily: 'Poppins'
                  ),
                ) ,
              ),
            ),
              ],
        ),
      ),
    );
  }
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật