Curso Flutter App Restaurant con Carrito
Implementar actions para mostrar notificaciones en Flutter
Notificaciones para mostrar Items | CURSO DE FLUTTER APP RESTAURANT CON CARRITO DE COMPRA [Part 11]
¿Cómo implementar notificaciones para un carrito de compra?
Para implementamos variables globales para el snackbar
final GlobalKey<ScaffoldState> _globalKey = new GlobalKey<ScaffoldState>();
...
child: Scaffold(
key: _globalKey,
backgroundColor: Colors.amber,
....
Implementación de actions en AppBar
appBar: AppBar(
title: Text("CARTA"),
backgroundColor: Colors.amber,
elevation: 0,
bottom: TabBar(
labelColor: Colors.red,
indicatorColor: Colors.red,
indicatorSize: TabBarIndicatorSize.label,
tabs: <Widget>[
new Tab(
child: Padding(
padding: EdgeInsets.only(left: 5, right: 5),
child: Text("PLATOS"),
),
),
new Tab(
child: Padding(
padding: EdgeInsets.only(left: 5, right: 5),
child: Text("BEBIDAS"),
),
),
new Tab(
child: Padding(
padding: EdgeInsets.only(left: 5, right: 5),
child: Text("POSTRES"),
),
)
],
),
actions: <Widget>[
new Stack(
children: <Widget>[
IconButton(
icon: Icon(Icons.shopping_cart),
onPressed: () {
carrito.numeroItems!=0 ?
Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext) => PantallaCarrito()
))
:
_globalKey.currentState.showSnackBar(SnackBar(
content: Text("Llenar el carrito", textAlign: TextAlign.center,),
));
}
),
new Positioned(
top: 6,
right: 6,
child: Container(
padding: EdgeInsets.all(2),
decoration: new BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(4)),
constraints: BoxConstraints(
minWidth: 14,
minHeight: 14
),
child: Text(
carrito.numeroItems.toString(),
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 10
),),
)
)
],
)
],
),
1862 visitas
Sigue con el curso: Capítulo 12 – Pantalla Carrito
Descarga el código fuente del proyecto adquiriendo el curso completo
Comprar© Todos los derechos reservados Codea App | ...de frente al código!!! | 2020 - 2023