Last active
August 14, 2020 17:44
-
-
Save guilhermecarvalhocarneiro/c254b84aee1dd76d25e6b2feef942f50 to your computer and use it in GitHub Desktop.
explorar.page.dart
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
/* | |
* Copyright (c) 2020. | |
* | |
* Desenvolvido por. | |
* Guilherme de Carvalho Carneiro | |
* guilherme.carvalho.carneiro@gmail.com | |
* | |
* Twitter -> https://twitter.com/GCarneiro | |
* Linkedin -> https://www.linkedin.com/in/guilhermecarvalho | |
* GitHub -> https://github.com/guilhermecarvalhocarneiro | |
*/ | |
import 'package:flutter/material.dart'; | |
import 'package:flutter_mobx/flutter_mobx.dart'; | |
import 'package:get_it/get_it.dart'; | |
import 'package:vestter_mobile/pages/home.page.dart'; | |
import 'package:vestter_mobile/source/explorar/controller.dart'; | |
import 'package:vestter_mobile/source/feed/controller.dart'; | |
import 'package:vestter_mobile/source/feed/model.dart'; | |
import 'package:vestter_mobile/source/feed/widgets/cardview.event.date.dart'; | |
import 'package:vestter_mobile/source/feed/widgets/cardview.feed.dart'; | |
import 'package:vestter_mobile/source/grupo/model.dart'; | |
import 'package:vestter_mobile/source/grupo/pages/index.page.dart'; | |
import 'package:vestter_mobile/source/usuario/controller.dart'; | |
import 'package:vestter_mobile/source/usuario/model.dart'; | |
import 'package:vestter_mobile/user_interface/color.dart'; | |
import 'package:vestter_mobile/user_interface/widget.dart'; | |
import '../app_localizations.dart'; | |
import 'explorer_filter.page.dart'; | |
class ExplorerPage extends StatefulWidget { | |
@override | |
_ExplorerPageState createState() => _ExplorerPageState(); | |
} | |
class _ExplorerPageState extends State<ExplorerPage> { | |
UserController _userController = GetIt.I<UserController>(); | |
FeedController _feedController = GetIt.I<FeedController>(); | |
ExplorarController _explorarController = GetIt.I<ExplorarController>(); | |
TextEditingController _searchController = TextEditingController(); | |
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>(); | |
@override | |
void initState() { | |
_explorarController.setWhatYouWantFilter( | |
true, true, true, null, null, null); | |
super.initState(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
key: _scaffoldKey, | |
backgroundColor: Color(vestterCustomGray), | |
appBar: AppBar( | |
elevation: 0, | |
title: Text( | |
AppLocalizations.of(context).translate("tabbar_explorar_label"), | |
style: TextStyle( | |
color: Colors.black, | |
), | |
), | |
centerTitle: true, | |
backgroundColor: Colors.white, | |
), | |
body: _buildBody(), | |
floatingActionButton: _buildFloatButton(), | |
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, | |
); | |
} | |
Widget _buildBody() { | |
return CustomScrollView( | |
slivers: <Widget>[ | |
_buildSearchComponent(), | |
SliverToBoxAdapter( | |
child: buildEventList(), | |
), | |
SliverToBoxAdapter( | |
child: buildFriendList(), | |
), | |
SliverToBoxAdapter( | |
child: buildGroupList(), | |
) | |
], | |
); | |
} | |
Widget _buildSearchComponent() { | |
return SliverAppBar( | |
backgroundColor: Colors.white, | |
pinned: false, | |
bottom: PreferredSize( | |
preferredSize: Size.fromHeight(15), | |
child: Container( | |
padding: const EdgeInsets.only( | |
top: 2, | |
left: 12, | |
right: 12, | |
bottom: 10, | |
), | |
child: Stack( | |
alignment: Alignment.center, | |
children: <Widget>[ | |
TextField( | |
textAlign: TextAlign.center, | |
autocorrect: false, | |
keyboardType: TextInputType.text, | |
controller: _searchController, | |
onSubmitted: (value) async => _searchData(value), | |
decoration: InputDecoration( | |
isDense: true, | |
hintText: | |
AppLocalizations.of(context).translate("label_pesquisar"), | |
hintStyle: TextStyle(color: Colors.black26), | |
enabledBorder: OutlineInputBorder( | |
borderSide: BorderSide(color: Colors.black26), | |
borderRadius: BorderRadius.all( | |
Radius.circular(50), | |
), | |
), | |
focusedBorder: OutlineInputBorder( | |
borderSide: BorderSide(color: Colors.black26), | |
borderRadius: BorderRadius.all( | |
Radius.circular(50), | |
), | |
), | |
), | |
), | |
Align( | |
alignment: Alignment.centerRight, | |
child: Padding( | |
padding: const EdgeInsets.only(right: 16.0), | |
child: GestureDetector( | |
child: Icon( | |
Icons.search, | |
color: Colors.black26, | |
size: MediaQuery.of(context).size.width * 0.060, | |
), | |
onTap: () async => _searchData( | |
_searchController.text.trim(), | |
), | |
), | |
), | |
) | |
], | |
), | |
), | |
), | |
); | |
} | |
void _searchData(String searchTerm) async { | |
FocusScopeNode currentFocus = FocusScope.of(context); | |
if (!currentFocus.hasPrimaryFocus) { | |
currentFocus.unfocus(); | |
} | |
_explorarController.searchEvents( | |
_userController.model, | |
searchTerm, | |
idCountry: _explorarController.countryFilterExplorer != null | |
? _explorarController.countryFilterExplorer.id ?? null | |
: null, | |
idState: _explorarController.stateFilterExplorer != null | |
? _explorarController.stateFilterExplorer.id ?? null | |
: null, | |
idCity: _explorarController.cityFilterExplorer != null | |
? _explorarController.cityFilterExplorer.id ?? null | |
: null, | |
); | |
_explorarController.searchUser( | |
_userController.model, | |
searchTerm, | |
idCountry: _explorarController.countryFilterExplorer != null | |
? _explorarController.countryFilterExplorer.id ?? null | |
: null, | |
idState: _explorarController.stateFilterExplorer != null | |
? _explorarController.stateFilterExplorer.id ?? null | |
: null, | |
idCity: _explorarController.cityFilterExplorer != null | |
? _explorarController.cityFilterExplorer.id ?? null | |
: null, | |
); | |
_explorarController.searchGroups( | |
_userController.model, | |
searchTerm, | |
idCountry: _explorarController.countryFilterExplorer != null | |
? _explorarController.countryFilterExplorer.id ?? null | |
: null, | |
idState: _explorarController.stateFilterExplorer != null | |
? _explorarController.stateFilterExplorer.id ?? null | |
: null, | |
idCity: _explorarController.cityFilterExplorer != null | |
? _explorarController.cityFilterExplorer.id ?? null | |
: null, | |
); | |
} | |
buildPostList() { | |
return Observer( | |
builder: (context) { | |
if (_feedController.processing == true) { | |
return Container( | |
height: 100, | |
child: Center( | |
child: CircularProgressIndicator(), | |
), | |
); | |
} else if (_feedController.errorMessage.isNotEmpty) { | |
return Center( | |
child: Text(_feedController.errorMessage), | |
); | |
} else { | |
return Container( | |
color: Color(vestterCustomGray), | |
padding: const EdgeInsets.only(bottom: 12), | |
child: ListView.builder( | |
shrinkWrap: true, | |
physics: ClampingScrollPhysics(), | |
itemCount: _feedController.list.length, | |
itemBuilder: (BuildContext context, int index) { | |
List<PostModel> itens = _feedController.list; | |
return FeedCardView( | |
context, | |
post: itens[index], | |
user: _userController.model, | |
); | |
}, | |
), | |
); | |
} | |
}, | |
); | |
} | |
buildEventList() { | |
return Observer( | |
builder: (context) { | |
if (_explorarController.whatYouWantFilter[2] == false) | |
return Container(); | |
if (_explorarController.processing == true) { | |
return Container( | |
height: 100, | |
child: Center( | |
child: CircularProgressIndicator(), | |
), | |
); | |
} else if (_explorarController.errorMessage.isNotEmpty) { | |
return Container( | |
height: 100, | |
child: Center( | |
child: Text(_explorarController.errorMessage), | |
), | |
); | |
} else { | |
if (_explorarController.events == null) { | |
return Container(); | |
} else { | |
return Container( | |
margin: const EdgeInsets.only(top: 12, bottom: 12), | |
color: Colors.white, | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
mainAxisSize: MainAxisSize.max, | |
children: <Widget>[ | |
Padding( | |
padding: const EdgeInsets.symmetric( | |
vertical: 16, horizontal: 12), | |
child: Text( | |
AppLocalizations.of(context) | |
.translate("feed_botao_filtro_eventos"), | |
style: TextStyle( | |
color: Color(0xFFFF5B00), | |
), | |
), | |
), | |
Visibility( | |
visible: _explorarController.events.length == 0, | |
child: buildEmptyResult(context), | |
), | |
Visibility( | |
visible: _explorarController.events.length > 0, | |
child: ListView.builder( | |
shrinkWrap: true, | |
physics: ClampingScrollPhysics(), | |
itemCount: _explorarController.events.length, | |
itemBuilder: (BuildContext context, int index) { | |
List<EventModel> itens = _explorarController.events; | |
EventModel _event = itens[index]; | |
return eventCardWithData( | |
context, _event, _userController.model); | |
}, | |
), | |
) | |
], | |
), | |
); | |
} | |
} | |
}, | |
); | |
} | |
buildFriendList() { | |
return Observer( | |
builder: (context) { | |
if (_explorarController.whatYouWantFilter[0] == false) | |
return Container(); | |
if (_explorarController.processing == true) { | |
return Container( | |
height: 100, | |
child: Center( | |
child: CircularProgressIndicator(), | |
), | |
); | |
} else if (_explorarController.errorMessage.isNotEmpty) { | |
return Container( | |
height: 100, | |
child: Center( | |
child: Text(_explorarController.errorMessage), | |
), | |
); | |
} else { | |
if (_explorarController.users == null) { | |
return Container(); | |
} else { | |
return Container( | |
color: Colors.white, | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.start, | |
crossAxisAlignment: CrossAxisAlignment.start, | |
mainAxisSize: MainAxisSize.max, | |
children: <Widget>[ | |
Padding( | |
padding: const EdgeInsets.symmetric( | |
vertical: 16, horizontal: 12), | |
child: Text( | |
AppLocalizations.of(context) | |
.translate("amigo_page_title"), | |
style: TextStyle( | |
color: Color(0xFFFF5B00), | |
), | |
), | |
), | |
Visibility( | |
visible: _explorarController.users.length == 0, | |
child: buildEmptyResult(context), | |
), | |
Visibility( | |
visible: _explorarController.users.length > 0, | |
child: ListView.builder( | |
shrinkWrap: true, | |
physics: ClampingScrollPhysics(), | |
itemCount: _explorarController.users.length, | |
itemBuilder: (BuildContext context, int index) { | |
UserModel _user = _explorarController.users[index]; | |
return InkWell( | |
onTap: () { | |
_detailUser(_user); | |
}, | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.start, | |
mainAxisSize: MainAxisSize.max, | |
children: <Widget>[ | |
Padding( | |
padding: const EdgeInsets.symmetric( | |
vertical: 14, horizontal: 12), | |
child: Row( | |
mainAxisAlignment: MainAxisAlignment.start, | |
children: <Widget>[ | |
circularImage( | |
_user.profilePhoto, | |
MediaQuery.of(context).size.width * | |
0.15, | |
MediaQuery.of(context).size.width * | |
0.15), | |
SizedBox(width: 8), | |
Text(_user.getName()) | |
], | |
), | |
), | |
Container( | |
margin: | |
const EdgeInsets.symmetric(vertical: 12), | |
height: 0.5, | |
color: Colors.black12, | |
), | |
], | |
), | |
); | |
}, | |
), | |
), | |
], | |
), | |
); | |
} | |
} | |
}, | |
); | |
} | |
buildGroupList() { | |
return Observer( | |
builder: (context) { | |
if (_explorarController.whatYouWantFilter[1] == false) | |
return Container(); | |
if (_explorarController.processing == true) { | |
return Container( | |
height: 100, | |
child: Center( | |
child: CircularProgressIndicator(), | |
), | |
); | |
} else if (_explorarController.errorMessage.isNotEmpty) { | |
return Center( | |
child: Text(_explorarController.errorMessage), | |
); | |
} else { | |
if (_explorarController.groups == null) { | |
return Container(); | |
} else { | |
return Container( | |
margin: const EdgeInsets.only(top: 12), | |
color: Colors.white, | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.start, | |
crossAxisAlignment: CrossAxisAlignment.start, | |
mainAxisSize: MainAxisSize.max, | |
children: <Widget>[ | |
Padding( | |
padding: const EdgeInsets.symmetric( | |
vertical: 16, horizontal: 12), | |
child: Text( | |
AppLocalizations.of(context) | |
.translate("grupo_page_title"), | |
style: TextStyle( | |
color: Color(0xFFFF5B00), | |
), | |
), | |
), | |
Visibility( | |
visible: _explorarController.groups.length == 0, | |
child: buildEmptyResult(context), | |
), | |
Visibility( | |
visible: _explorarController.groups.length > 0, | |
child: ListView.builder( | |
shrinkWrap: true, | |
physics: ClampingScrollPhysics(), | |
itemCount: _explorarController.groups.length, | |
itemBuilder: (BuildContext context, int index) { | |
GroupModel group = _explorarController.groups[index]; | |
return InkWell( | |
onTap: () async { | |
Navigator.push( | |
context, | |
MaterialPageRoute( | |
builder: (context) => GrupoIndexPage( | |
groupDetail: group, | |
forceGetDetail: true, | |
), | |
), | |
); | |
}, | |
child: Container( | |
padding: const EdgeInsets.symmetric( | |
vertical: 12, | |
horizontal: 4, | |
), | |
width: double.infinity, | |
child: Row( | |
mainAxisAlignment: MainAxisAlignment.start, | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: <Widget>[ | |
circularImage( | |
group.image, | |
MediaQuery.of(context).size.width * 0.15, | |
MediaQuery.of(context).size.width * 0.15, | |
), | |
Padding( | |
padding: const EdgeInsets.all(8.0), | |
child: Column( | |
crossAxisAlignment: | |
CrossAxisAlignment.start, | |
children: <Widget>[ | |
Text(group.getName), | |
Text(group.getLocation), | |
], | |
), | |
), | |
Spacer(), | |
Row( | |
children: <Widget>[ | |
Text(group.getDistance), | |
], | |
), | |
], | |
), | |
), | |
); | |
}, | |
), | |
), | |
], | |
), | |
); | |
} | |
} | |
}, | |
); | |
} | |
Container buildEmptyResult(BuildContext context) { | |
return Container( | |
padding: const EdgeInsets.only(top: 6, bottom: 16), | |
width: double.infinity, | |
child: Text( | |
AppLocalizations.of(context).translate("label_retorno_vazio"), | |
textAlign: TextAlign.center, | |
), | |
); | |
} | |
Widget _buildFloatButton() { | |
return InkWell( | |
onTap: () async { | |
final result = await Navigator.push( | |
context, | |
MaterialPageRoute( | |
builder: (_) => ExplorerFilterPage(), | |
), | |
); | |
if (result != null && result == true) { | |
_searchData(""); | |
} | |
}, | |
child: Container( | |
margin: const EdgeInsets.symmetric(vertical: 12, horizontal: 32), | |
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 4), | |
decoration: BoxDecoration( | |
color: Colors.black, | |
borderRadius: BorderRadius.circular(50), | |
), | |
child: Row( | |
mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
mainAxisSize: MainAxisSize.min, | |
children: <Widget>[ | |
Icon(Icons.filter_list, color: Colors.white), | |
SizedBox(width: 12), | |
Text( | |
AppLocalizations.of(context) | |
.translate("explorar_configuracao_filtrar") | |
.toUpperCase(), | |
style: TextStyle(color: Colors.white), | |
), | |
Container( | |
margin: const EdgeInsets.only(left: 12), | |
width: 25, | |
height: 25, | |
decoration: BoxDecoration( | |
gradient: orangeGradienteInverse(), | |
borderRadius: BorderRadius.circular(50), | |
), | |
child: Observer(builder: (_) { | |
return Align( | |
alignment: Alignment.center, | |
child: Text( | |
"+${_explorarController.whatYouWantFilter.where((value) => value == true).toList().length}", | |
style: TextStyle(color: Colors.white, fontSize: 14), | |
), | |
); | |
}), | |
) | |
], | |
), | |
), | |
); | |
} | |
_detailUser(UserModel usuario) async { | |
_userController.setProcessingAuthoPostProfile(true); | |
_userController.authorPostShowProfileTab = true; | |
_feedController.listAuthor?.clear(); | |
Navigator.push( | |
context, | |
MaterialPageRoute( | |
builder: (_) => HomePage( | |
autor: usuario, | |
accessFromEditProfilePage: false, | |
accessFromLoginPage: false, | |
), | |
), | |
); | |
} | |
// showLoadingModal({show = false}) { | |
// if (show) { | |
// processingDialog(context); | |
// } else { | |
// // Ocultando o Dialog | |
// Navigator.of(context).pop(); | |
// } | |
// } | |
// showMessage(String mensagem, {error = false}) { | |
// var snackBar = SnackBar( | |
// content: Text(mensagem), | |
// backgroundColor: error ? Colors.red : Colors.black); | |
// _scaffoldKey.currentState.showSnackBar(snackBar); | |
// } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment