Created
July 23, 2019 19:58
-
-
Save guilhermecarvalhocarneiro/bc693b770d7e928078264b15b241fec6 to your computer and use it in GitHub Desktop.
Uma das página da tab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:bloc_pattern/bloc_pattern.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:minhacidade/blocs/evento_bloc.dart'; | |
import 'package:minhacidade/pages/evento_page.dart'; | |
import 'package:minhacidade/widgets/card_widget.dart'; | |
class EventosPage extends StatefulWidget { | |
EventosPage({Key key}) : super(key: key); | |
_EventosPageState createState() => _EventosPageState(); | |
} | |
class _EventosPageState extends State<EventosPage> | |
with AutomaticKeepAliveClientMixin<EventosPage> { | |
final _eventoBloc = BlocProvider.getBloc<EventoBloc>(); | |
@override | |
bool get wantKeepAlive => true; | |
@override | |
void initState() { | |
super.initState(); | |
_eventoBloc.getEventos(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
super.build(context); | |
return Container( | |
color: Colors.white, | |
child: Padding( | |
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16), | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: <Widget>[ | |
Expanded( | |
child: RefreshIndicator( | |
onRefresh: (() async { | |
_eventoBloc.getUpdate(); | |
}), | |
child: StreamBuilder( | |
stream: _eventoBloc.stream, | |
builder: (context, snapshot) { | |
switch (snapshot.connectionState) { | |
case ConnectionState.none: | |
case ConnectionState.waiting: | |
return Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Image.asset( | |
'assets/images/logo.png', | |
scale: 2, | |
), | |
Text('Carregando...'), | |
], | |
), | |
); | |
default: | |
if (snapshot.hasError) { | |
return _dataEmpty( | |
"Ocorreu um erro, favor tentar novamente"); | |
} else if (snapshot.hasData) { | |
if (snapshot.data.length != 0) { | |
return _createListView(snapshot.data); | |
} else { | |
return _dataEmpty("Nenhum evento encontrado"); | |
} | |
} else { | |
return _dataEmpty("Nenhum evento encontrado"); | |
} | |
} | |
}, | |
), | |
), | |
) | |
], | |
), | |
), | |
); | |
} | |
ListView _createListView(eventos) { | |
return ListView.builder( | |
itemCount: eventos.length, | |
itemBuilder: (context, index) { | |
var evento = eventos[index]; | |
return GestureDetector( | |
onTap: () { | |
Navigator.push(context, MaterialPageRoute( | |
builder: (context) => EventoPage(evento: evento,) | |
)); | |
}, | |
child: Container( | |
margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 8), | |
child: Column( | |
children: <Widget>[ | |
Hero( | |
tag: 'eventoImage${evento.id}', | |
child: imageCardRoundTop(context, evento.getImage(), | |
imageAssets: true, elevation: 2.0), | |
), | |
cardBorderRadius( | |
context, | |
Column( | |
crossAxisAlignment: CrossAxisAlignment.end, | |
children: <Widget>[ | |
Container( | |
width: MediaQuery.of(context).size.width, | |
child: Align( | |
alignment: Alignment.bottomRight, | |
child: Text( | |
evento.titulo, | |
style: Theme.of(context) | |
.textTheme | |
.display1 | |
.copyWith(color: Colors.black54), | |
), | |
), | |
), | |
Text( | |
evento.horario, | |
style: Theme.of(context) | |
.textTheme | |
.display1 | |
.copyWith(color: Colors.black54), | |
), | |
Text( | |
"R\$ ${evento.valor.toString().replaceAll(".", ",")}", | |
style: Theme.of(context) | |
.textTheme | |
.display1 | |
.copyWith(color: Colors.black54), | |
), | |
], | |
), | |
topLeft: 0.0, | |
topRight: 0.0, | |
elevation: 1.0, | |
bgColor: Colors.white), | |
], | |
), | |
), | |
); | |
}, | |
); | |
} | |
_dataEmpty(String mensagem) { | |
return Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Image.asset( | |
'assets/images/logo.png', | |
scale: 2, | |
), | |
Text(mensagem, style: Theme.of(context).textTheme.body1.copyWith(fontSize: 18),), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment