-1
my main layout features an aapBar, body and bottomNavigationBar through the bottomNavigationBar I update the body with other screens, which show a listview, in the appBar from the main screen I have a delete all button, I can not update the Listview from the open screen in body... The data from this Listview comes from a Futurebuilder, how can I do that? Darpat: Example on the Dartpad
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: MyWidget(),
);
}
}
class MyWidget extends StatefulWidget {
@override
_MyWidgetState createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
_menuSel(String itemText) {
switch (itemText) {
case "Marcar todos":
print("ItemSel Marcar todos");
break;
case "Desmarcar todos":
print("Excluindo registros do banco e atualizar liste view Tela1");
//função exclui itens do bd atualizar Scaffold/ListView em Tela1 ou Tela2
break;
}
}
int _indiceNav = 0;
List<String> itensMenu = ["Marcar todos", "Desmarcar todos"];
List<Widget> telas = [
Tela1(),
Tela2(),
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title: Text("principal"),
actions: <Widget>[
IconButton(
icon: Icon(Icons.search),
onPressed: () {},
),
PopupMenuButton<String>(
onSelected: _menuSel,
itemBuilder: (context) {
return itensMenu.map((String item) {
return PopupMenuItem<String>(
value: item,
child: Text(item),
);
}).toList();
},
),
],
),
body: telas[_indiceNav],
bottomNavigationBar: BottomNavigationBar(
currentIndex: _indiceNav,
onTap: (indice) {
print("pressionado $indice");
setState(() {
_indiceNav = indice;
});
},
items: [
BottomNavigationBarItem(
title: Text("Tela1"), icon: Icon(Icons.alarm)),
BottomNavigationBarItem(
title: Text("Tela2"), icon: Icon(Icons.list)),
]),
);
}
}
class Tela1 extends StatefulWidget {
@override
_Tela1State createState() => _Tela1State();
}
class _Tela1State extends State<Tela1> {
@override
Widget build(BuildContext context) {
return Text("TEla 1");
//return Scaffold(body: FutureBuilder... ListView...);
}
}
class Tela2 extends StatefulWidget {
@override
_Tela2State createState() => _Tela2State();
}
class _Tela2State extends State<Tela2> {
@override
Widget build(BuildContext context) {
return Text("TEla 2");
//return Scaffold(body: FutureBuilder... ListView...);
}
}
In the main project, Tela1, and Tela2 are separate files. In short, I need to access methods and update the open body screens!
Your question is a little confused and in your example there is no
ListView
... Just so I’m clear, you owned oneBottomNavigator
with 2 tabs, each one with its respectiveListView
and when you click on the "Delete all" button, you want it to be cleanedListView
of the tab being displayed, that’s it?– Matheus Ribeiro
Exactly, the list is being filled in a Futurebuilder of data of an API, I did not put this part of the code not to be too extensive.. everything is working, including deletion of data from BD, I just need to update the screen where the listview is.
– MariINova