0
Hello, I’m seeking to reuse some widgets from my app, I’ll give a brief example.
I have an Appbar, which in case is my General Menu, present on all screens.
import 'package:flutter/material.dart';
class MenuGeral extends StatelessWidget implements PreferredSize {
bool exibirConteudo = false;
@override
Size get preferredSize => const Size.fromHeight(100);
Widget build(BuildContext context) {
return AppBar( // CABEÇALHO
title: "Text",
actions: <Widget>[
IconButton(
icon: Icon(Icons.menu,color: Colors.white),
onPressed: (){
exibirConteudo= !exibirConteudo;
print("$exibirConteudo");
}
)
],
...
);
}
As seen, it has a variable called displayConteud
I need to pass this variable displayConference to another screen call
import 'package:flutter/material.dart';
import 'package:meuPackage/widgets/menu_geral.dart';
class Home extends StatefulWidget {
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
bool _exibirConteudo = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: MenuGeral(),
body: Visibility(
visible: exibirConteudo,
return widgetQueQueroExibir(),
)
...
);
}
I already managed to put the widget on the necessary screens, but I can’t get the value of the active variable.
I need to take the value of this variable, because in the body of my Home, has a Visibility widget that receives this value, to obviously display or not another Widget
What is a good way to do this, without giving a Navigator.Placement passing the variable from the Menugeral?
Briefly, I want to be able to use a Boolean variable from a reusable Widget (Stateless) on all other screens of my app (Statefull), to perform an action, without using Navigator.push, if possible.
Thank you for your attention, I will seek to learn about state management. Your answer although dedicated does not solve my problem, after all what I need is a kind of switch, On and Off, alternating whenever the button is clicked. I implemented its function, but it will only deny the startup constant of the general menu. That is, it displays the widget, but if I click again it does not close. Anyway thanks.
– Lucas santos
Can you just answer one question? It’s still about this problem, I researched the Bloc standard, implemented it, but my Streambuilder only gets the first update. ?
– Lucas santos