I'm creating an Flutter application. And I'm 3-th day can't to add items to ListView manually with 'Add' button.
I'm tried to use setState, but it doesn't work in Stateless widget. Because I have a route from Stateful widget to Stateless. I'm using Navigator.push(...).
Then I'm tried to use Cubit, but it doesn't work. Flutter - BloC Cubit function doesn't emitting state
What can I do?
[Code is so large. I'm uploaded the neccessary part]
Home Page (Stateful Widget)
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
State of Stateful Widget
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: 'List App',
actions: [
IconButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SearchPage())
);
}
])
})
SearchPage (With ListView)
class SearchPage extends StatelessWidget {
const SearchPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return DefaultTabController(
child: Builder(builder: (BuildContext context) {
final TabController tabController = DefaultTabController.of(context)!;
tabController.addListener(() {
if (!tabController.indexIsChanging) {
}
});
return Scaffold(
body: (context, items) => TabBarView(
children: [
Container(
child: FutureBuilder(
future: items_client.getItems(),
builder: (BuildContext context, AsyncSnapshot<List<Item>> snapshot) {
if (snapshot.hasData) {
items = snapshot.data!;
return ListView(
children: items.asMap()
.map(
(i, item) => MapEntry(i,
Column(
children: [
Text('${item.name'})
]
))
)
}
}
)
]
)
)
}
}