Hello, I'm trying to make an app where I can store data inputted by the user like this one. My task is to use SharedPreferences to store the data.
I used SharedPreferences to save the data in a List
saveData() async {
List<String> itemData = [];
itemData.add(fstcontroller.text);
itemData.add(sndcontroller.text);
itemData.add(trdcontroller.text);
itemData.add(fthcontroller.text);
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setStringList("item", itemData);
}
I have 2 problems, First Problem: whenever I click the Show Cart button, it shows this one
I don't want to display like this, I want to only display the "Item Brand", the rest will not be displayed. Then, if I click the cell, it will display the full details of the item in the third screen.
here's the SecondScreen
class SecondScreen extends StatefulWidget {
@override
State createState() => new DynamicList();
}
class DynamicList extends State<SecondScreen> {
List<String> listItems = [];
@override
void initState() {
super.initState();
getUser();
}
getUser() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
var itemData = prefs.getStringList("item");
setState(() {
listItems = itemData;
});
}
@override
Widget build(BuildContext context) {
return new Scaffold(
body: Column(
children: <Widget>[
Expanded(
child: ListView.builder(
itemCount: listItems.length, itemBuilder: buildList),
)
],
),
);
}
Widget buildList(BuildContext context, int index) {
return Container(
margin: EdgeInsets.all(4),
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
width: 2,
),
borderRadius: BorderRadius.circular(5)),
child: ListTile(
title: Text(listItems[index]),
),
);
}
}
Second problem: Whenever I add multiple data, the data doesn't stack. It only replaces the data.

