0

I have Object list, my list is built with multiple types of data (Int, String, List of bool, list of String, bool...), from that list I want to save the data of some bool variables (for example when I tap a button). Is there any way to save that changed bools instead of save all the data? If the only way to save the data is saving all the list, how I can do that?

I see on internet that I have to map my list first in order to get it back later, only with map because my list is not a list of Strings, however I don't understand how to implement that, and how to get data back later, any idea ?

Example of one list I used:

import 'dart:ui';

class DefinitiveList {

  int id;
  String num;
  String name;
  bool like; //variable I want to save
  bool catched; //variable I want to save

  DefinitiveList(
    this.id,
    this.num,
    this.name,
    this.like, 
    this.catched

  );
}




final List<DefinitiveList> definiti = [ //DefinitiveList is a class
  DefinitiveList(
    1, //id, 
   "88", //num
    "Eli", //name
    true, //like
    false, //catched

    ),

  DefinitiveList(
    2, //id, 
   "17", //num
    "Juan", //name
    false, //like
    false, //catched

    ),]

UPDATE:

here is a example list of my code:

Widget listView() {
    int columnCount = 3;
    final deviceWidth = MediaQuery.of(context).size.width;
    return AnimationLimiter(
      child: ListView.builder(
          controller: myScrollController,
          padding: EdgeInsets.only(
            top: 10.0,
          ),
          itemCount: definiti.length,
          key: PageStorageKey<String>(
              'listsave'), 
          itemBuilder: (context, index) {
            final dlists = definiti[index];

            return GestureDetector(
              onTap: () {
                dlists.like = !like; //I want to retrieve this
               dlists.catched = !catched; //I want to retrieve this
              },
              child: Padding(
                padding: EdgeInsets.only(
                  bottom: 25.0,
                  right: 20.0,
                  left: 20.0,
                ),
                child:
                    Stack(alignment: Alignment.centerLeft, children: <Widget>[
                  Container(
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(25),
                      // ignore: prefer_const_literals_to_create_immutables
                      boxShadow: [
                        shadows.BoxShadow(
                          blurRadius: 10,
                          offset: Offset(10, 10),
                          spreadRadius: 1,
                          color: Constant.isDarkMode
                              ? Constant.greShadowDark
                              : Constant.greShadowLight,
                        )
                      ],
                      color: Constant.isDarkMode
                          ? Constant.darktMode
                          : Constant.lightMode,
                    ),
                    child: Padding(
                      padding: EdgeInsets.symmetric(
                        horizontal: 20.0,
                        vertical: 20.0,
                      ),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          SizedBox(
                            width: deviceWidth * 0.34,
                          ),
                          Flexible(
                            child: Column(
                                mainAxisAlignment: MainAxisAlignment
                                    .center, //Center Column contents vertically,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: <Widget>[
                                  Row(
                                    mainAxisAlignment: MainAxisAlignment
                                        .center, //Center Row contents horizontally,
                                    crossAxisAlignment:
                                        CrossAxisAlignment.center,
                                    children: <Widget>[
                                      Text(
                                        dlists.name, //NOOOOOOMBRE
                                        style: TextStyle(
                                          fontSize: 22.0,
                                          color: Constant.isDarkMode
                                              ? Colors.grey
                                              : Colors.black,
                                          fontWeight: FontWeight.bold,
                                        ),
                                      ),
                                  
                                    ],
                                  ),
                                 
                                  SizedBox(
                                    height: 20.0,
                                  ),
                                  Row(
                                      mainAxisAlignment: MainAxisAlignment
                                          .center, //Center Row contents horizontally,
                                      crossAxisAlignment:
                                          CrossAxisAlignment.center,
                                      children: [
                                        ZoomIn(
                                          child: InkWell(
                                            onTap: () {},
                                            child: Container(
                                              //margin: const EdgeInsets.all(10.0),
                                              decoration: BoxDecoration(
                                                  boxShadow: [
                                                    shadows.BoxShadow(
                                                        blurRadius: 7,
                                                        offset: Offset(-7, -7),
                                                        color: Constant
                                                                .isDarkMode
                                                            ? Constant
                                                                .whiteShadowDark
                                                            : Constant
                                                                .whiteShadowLight,
                                                        inset: true,
                                                        spreadRadius: 1),
                                                    shadows.BoxShadow(
                                                      blurRadius: 7,
                                                      offset: Offset(7, 7),
                                                      spreadRadius: 1,
                                                      color: Constant.isDarkMode
                                                          ? Constant
                                                              .greShadowDark
                                                          : Constant
                                                              .greShadowLight,
                                                    )
                                                  ],
                                                  // ignore: prefer_const_literals_to_create_immutables

                                                  shape: BoxShape.rectangle,
                                                  borderRadius:
                                                      BorderRadius.only(
                                                          topLeft:
                                                              Radius.circular(
                                                                  15.0),
                                                          topRight:
                                                              Radius.circular(
                                                                  15.0),
                                                          bottomRight:
                                                              Radius.circular(
                                                                  15.0),
                                                          bottomLeft:
                                                              Radius.circular(
                                                                  15.0))),
                                              width: MediaQuery.of(context)
                                                      .size
                                                      .width *
                                                  0.20,
                                              height: MediaQuery.of(context)
                                                      .size
                                                      .width *
                                                  0.080,
                                              // ignore: prefer_const_constructors
                                              child: Center(
                                                child: Text(
                                                  dlists.type1,
                                                  style: GoogleFonts.rubik(
                                                    fontSize: 15,
                                                    color: Colors.white,
                                                  ),
                                                ),
                                              ),
                                            ),
                                          ),
                                        ),
                                      ]),
                                ]),
                          ),
                        ],
                      ),
                    ),
                  ),
                ]),
              ),
            );
          }),
    );
  }

0 Answers0