Created
April 6, 2021 13:55
-
-
Save guilhermecarvalhocarneiro/c3c90d1cd266431afda0763882ee420c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| class FeedCardView extends StatefulWidget { | |
| final PostModel post; | |
| final UserModel user; | |
| final UserModel loggedUser; | |
| final double elevation; | |
| final double topLeft; | |
| final double topRight; | |
| final double bottomRight; | |
| final double bottomLeft; | |
| final Color bgColor; | |
| final bool otherUserFeed; | |
| final double offsetListViewPosition; | |
| FeedCardView( | |
| BuildContext context, { | |
| Key key, | |
| this.post, | |
| this.user, | |
| this.loggedUser, | |
| this.elevation = 0.0, | |
| this.topLeft = 5.0, | |
| this.topRight = 5.0, | |
| this.bottomLeft = 5.0, | |
| this.bottomRight = 5.0, | |
| this.bgColor = Colors.white54, | |
| this.otherUserFeed = false, | |
| this.offsetListViewPosition, | |
| }) : super(key: key); | |
| @override | |
| _FeedCardViewState createState() => _FeedCardViewState(); | |
| } | |
| class _FeedCardViewState extends State<FeedCardView> { | |
| bool rocketIt; | |
| bool userIsUserLogged; | |
| @override | |
| void initState() { | |
| super.initState(); | |
| rocketIt = widget.post.rockedIt ?? false; | |
| userIsUserLogged = widget.post.userData.userIsUserLogged; | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return Card( | |
| clipBehavior: Clip.antiAliasWithSaveLayer, | |
| child: Padding( | |
| padding: const EdgeInsets.only(top: 8, bottom: 2), | |
| child: Column( | |
| crossAxisAlignment: CrossAxisAlignment.stretch, | |
| children: <Widget>[ | |
| _buildHeadPostCard(context), | |
| Offstage( | |
| offstage: widget.post.postPhotos.isEmpty, | |
| child: InkWell( | |
| onTap: () { | |
| _detailPost(context, widget.post); | |
| }, | |
| child: buildPicturePost(widget.post), | |
| ), | |
| ), | |
| Offstage( | |
| offstage: widget.post.getMessage().isEmpty, | |
| child: Column( | |
| mainAxisSize: MainAxisSize.min, | |
| children: [ | |
| Container( | |
| height: 1, | |
| width: double.infinity, | |
| color: Color(vestterColorBlackCyan).withOpacity(0.08), | |
| ), | |
| InkWell( | |
| onTap: () { | |
| _detailPost(context, widget.post); | |
| }, | |
| child: Padding( | |
| padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 8.0), | |
| child: Text( | |
| widget.post.getMessage(limited: 100), | |
| ), | |
| ), | |
| ), | |
| Container( | |
| height: 1, | |
| width: double.infinity, | |
| color: Color(vestterColorBlackCyan).withOpacity(0.08), | |
| ), | |
| ], | |
| ), | |
| ), | |
| Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: <Widget>[ | |
| Expanded( | |
| child: InkWell( | |
| child: Container( | |
| height: 48, | |
| child: Center( | |
| child: Row( | |
| mainAxisAlignment: MainAxisAlignment.center, | |
| children: <Widget>[ | |
| widget.post.rockedIt || rocketIt | |
| ? Image.asset('assets/images/icone-rock-active.png', width: 20.0) | |
| : Image.asset('assets/images/icone-rock.png', width: 20.0), | |
| Padding( | |
| padding: const EdgeInsets.only(left: 8.0), | |
| child: Text( | |
| AppLocalizations.of(context).translate("feed_post_curtir"), | |
| textAlign: TextAlign.center, | |
| style: TextStyle( | |
| color: widget.post.rockedIt || rocketIt ? Colors.orange : Color(vestterColorBlack), | |
| fontWeight: FontWeight.w600, | |
| ), | |
| ), | |
| ), | |
| ], | |
| ), | |
| ), | |
| ), | |
| onTap: () { | |
| setState(() { | |
| rocketIt = !rocketIt; | |
| }); | |
| rockItUnRockIt(context, widget.post); | |
| }, | |
| ), | |
| ), | |
| Expanded( | |
| child: InkWell( | |
| child: Container( | |
| height: 48, | |
| child: Center( | |
| child: Row( | |
| mainAxisAlignment: MainAxisAlignment.center, | |
| children: <Widget>[ | |
| Image.asset('assets/images/icone-comentario.png', width: 20.0), | |
| Padding( | |
| padding: const EdgeInsets.only(left: 8.0), | |
| child: Text( | |
| AppLocalizations.of(context).translate("feed_post_comentar"), | |
| textAlign: TextAlign.center, | |
| style: TextStyle( | |
| color: Color(vestterColorBlack), | |
| fontWeight: FontWeight.w600, | |
| ), | |
| ), | |
| ), | |
| ], | |
| ), | |
| ), | |
| ), | |
| onTap: () { | |
| _detailPost(context, widget.post); | |
| }, | |
| ), | |
| ), | |
| ]) | |
| ], | |
| ), | |
| ), | |
| shape: RoundedRectangleBorder( | |
| borderRadius: BorderRadius.only( | |
| topLeft: Radius.circular(0.0), | |
| topRight: Radius.circular(0.0), | |
| bottomLeft: Radius.circular(0.0), | |
| bottomRight: Radius.circular(0.0), | |
| ), | |
| ), | |
| elevation: widget.elevation, | |
| margin: const EdgeInsets.only(top: 10), | |
| ); | |
| } | |
| buildProfilePicture(BuildContext context, post) { | |
| if (post.userData.profilePhoto == null || post.userData.profilePhoto.isEmpty == true) { | |
| return circularAssetImage( | |
| 'assets/images/no-photo.png', | |
| MediaQuery.of(context).size.width * 0.095, | |
| MediaQuery.of(context).size.width * 0.095, | |
| ); | |
| } | |
| return CachedNetworkImage( | |
| imageUrl: post.userData.profilePhoto, | |
| imageBuilder: (context, imageProvider) => Container( | |
| height: MediaQuery.of(context).size.width * 0.095, | |
| width: MediaQuery.of(context).size.width * 0.095, | |
| decoration: BoxDecoration( | |
| shape: BoxShape.circle, | |
| image: DecorationImage(image: imageProvider, fit: BoxFit.cover), | |
| ), | |
| ), | |
| fadeInDuration: const Duration(milliseconds: 1), | |
| fadeOutDuration: const Duration(milliseconds: 1), | |
| errorWidget: (context, url, error) => Image.asset( | |
| 'assets/images/logo_vestter.png', | |
| width: 48, | |
| ), | |
| ); | |
| } | |
| buildPicturePost(PostModel post) { | |
| try { | |
| if (post.postPhotos != null && post.postPhotos.length > 0) { | |
| return PhotosCarousel(photos: post.postPhotos); | |
| } else { | |
| return Container(); | |
| } | |
| } catch (e) { | |
| return Container(); | |
| } | |
| } | |
| Widget _buildAlertMarker(BuildContext context, PostModel post) { | |
| if (post.isAlert() == true) { | |
| return Row( | |
| crossAxisAlignment: CrossAxisAlignment.center, | |
| children: <Widget>[ | |
| Image.asset('assets/images/icone-emergencia.png', width: MediaQuery.of(context).size.width * 0.050), | |
| SizedBox(width: 4), | |
| Padding( | |
| padding: const EdgeInsets.only(top: 4.0), | |
| child: Text( | |
| AppLocalizations.of(context).translate("feed_post_alerta_label"), | |
| style: TextStyle(color: Color(0xFFFff681e), fontSize: MediaQuery.of(context).size.width * 0.035), | |
| ), | |
| ), | |
| ], | |
| ); | |
| } else { | |
| return Container(); | |
| } | |
| } | |
| _detailPost(BuildContext context, PostModel post) { | |
| // Recuperando o Controller do Feed | |
| FeedController _feedController = GetIt.I<FeedController>(); | |
| _feedController.modelDetail = post; | |
| /// Método para chamar uma tela sobrepondo a TabBar | |
| showCupertinoDialog(context: context, builder: (_) => CommentPostPage()); | |
| } | |
| /// Método para pegar os detalhes do author do post | |
| _detailOtherUser(BuildContext context, PostModel post) async { | |
| UserModel _authorPost = post.userData; | |
| NavigationController _navigationController = GetIt.I<NavigationController>(); | |
| _navigationController.changeFeedIsShowingSubPage(); | |
| Navigator.push( | |
| context, | |
| CupertinoPageRoute( | |
| builder: (_) => ProfileOtherUserPage(otherUser: _authorPost), | |
| ), | |
| ); | |
| } | |
| /// Método para curtir ou descurtir a postagem | |
| /// Param: | |
| /// context -> Contexto | |
| /// post -> Instância do PostModel | |
| Future rockItUnRockIt(BuildContext context, PostModel post) async { | |
| // Recuperando o Controller do Usuario | |
| UserController _userController = GetIt.I<UserController>(); | |
| // Recuperando o Controller do Feed | |
| FeedController _feedController = GetIt.I<FeedController>(); | |
| try { | |
| _feedController.rockItUnRockIt(_userController.model, post); | |
| } catch (e) { | |
| DebugPrint.erro("Erro ao executar o rockIt no CardView: $e"); | |
| } | |
| return null; | |
| } | |
| // Método para mostrar o modal de detalhamento/exclusão | |
| _showModal(BuildContext context, PostModel post) { | |
| // Recuperando o Controller do Usuario | |
| UserController _usuarioController = GetIt.I<UserController>(); | |
| // Recuperando o Controller do Feed | |
| FeedController _feedController = GetIt.I<FeedController>(); | |
| showModalBottomSheet( | |
| backgroundColor: Colors.transparent, // Removendo a cor de background | |
| context: context, | |
| builder: (BuildContext bc) { | |
| return Padding( | |
| padding: const EdgeInsets.all(4.0), | |
| child: Container( | |
| child: Padding( | |
| padding: const EdgeInsets.all(8.0), | |
| child: Wrap( | |
| children: <Widget>[ | |
| Container( | |
| width: double.infinity, | |
| decoration: BoxDecoration( | |
| color: Colors.grey[800], | |
| borderRadius: BorderRadius.all(Radius.circular(8)), | |
| ), | |
| child: Column( | |
| children: <Widget>[ | |
| InkWell( | |
| onTap: () { | |
| // Setando o post que será editado no controller | |
| _feedController.model = post; | |
| Navigator.pushReplacement( | |
| context, | |
| MaterialPageRoute( | |
| builder: (context) => NewPostPage(), | |
| ), | |
| ); | |
| }, | |
| child: Container( | |
| width: double.infinity, | |
| padding: const EdgeInsets.symmetric(vertical: 12.0), | |
| child: Center( | |
| child: Text( | |
| AppLocalizations.of(context).translate("feed_post_editar_label"), | |
| style: TextStyle(color: Colors.blue), | |
| ), | |
| ), | |
| ), | |
| ), | |
| Divider(height: 1, color: Colors.white54), | |
| InkWell( | |
| onTap: () { | |
| Navigator.pop(context); | |
| showDialog( | |
| context: context, | |
| builder: (BuildContext context) { | |
| return AlertDialog( | |
| title: Text( | |
| AppLocalizations.of(context).translate("feed_card_confirmar_exclusao_titulo"), | |
| ), | |
| content: null, | |
| actions: [ | |
| FlatButton( | |
| onPressed: () { | |
| Navigator.pop(context); | |
| }, | |
| child: Text( | |
| AppLocalizations.of(context) | |
| .translate("feed_card_confirmar_exclusao_cancelar"), | |
| ), | |
| ), | |
| FlatButton( | |
| onPressed: () { | |
| Navigator.pop(context); | |
| _feedController.delete(_usuarioController.model, post); | |
| }, | |
| child: Text( | |
| AppLocalizations.of(context).translate("feed_card_confirmar_exclusao_ok"), | |
| ), | |
| ) | |
| ]); | |
| }); | |
| }, | |
| child: Container( | |
| width: double.infinity, | |
| padding: const EdgeInsets.symmetric(vertical: 12.0), | |
| child: Center( | |
| child: Text( | |
| AppLocalizations.of(context).translate("feed_post_delete_label"), | |
| style: TextStyle(color: Colors.red), | |
| ), | |
| ), | |
| ), | |
| ), | |
| ], | |
| ), | |
| ), | |
| Padding( | |
| padding: EdgeInsets.only(top: 10.0, bottom: heightBottomNavigationBar), | |
| child: InkWell( | |
| onTap: () { | |
| Navigator.pop(context); | |
| }, | |
| child: Container( | |
| width: double.infinity, | |
| decoration: BoxDecoration( | |
| color: Colors.grey[850], | |
| borderRadius: BorderRadius.all( | |
| Radius.circular(8), | |
| ), | |
| ), | |
| child: Padding( | |
| padding: const EdgeInsets.symmetric(vertical: 12.0), | |
| child: Center( | |
| child: Text( | |
| AppLocalizations.of(context).translate("feed_post_cancelar_label"), | |
| style: TextStyle( | |
| color: Colors.blue, | |
| fontWeight: FontWeight.bold, | |
| ), | |
| ), | |
| ), | |
| ), | |
| ), | |
| ), | |
| ) | |
| ], | |
| ), | |
| ), | |
| ), | |
| ); | |
| }, | |
| ); | |
| } | |
| /// Método para construir a área do cabeçalho do card do Post | |
| Widget _buildHeadPostCard(BuildContext context) { | |
| return Padding( | |
| padding: const EdgeInsets.only(bottom: 8, left: 8, right: 8), | |
| child: Row( | |
| mainAxisSize: MainAxisSize.max, | |
| mainAxisAlignment: MainAxisAlignment.start, | |
| children: <Widget>[ | |
| InkWell( | |
| onTap: userIsUserLogged || widget.user == widget.loggedUser | |
| ? null | |
| : () { | |
| _detailOtherUser(context, widget.post); | |
| }, | |
| child: buildProfilePicture(context, widget.post), | |
| ), | |
| SizedBox( | |
| width: 10, | |
| ), | |
| Expanded( | |
| child: Column( | |
| // Coluna dos dados do autor do Post | |
| crossAxisAlignment: CrossAxisAlignment.start, | |
| children: <Widget>[ | |
| Row( | |
| mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
| children: <Widget>[ | |
| Expanded( | |
| child: InkWell( | |
| onTap: userIsUserLogged || widget.user == widget.loggedUser | |
| ? null | |
| : () { | |
| _detailOtherUser(context, widget.post); | |
| }, | |
| child: Text( | |
| widget.post.userData.getName(), | |
| style: TextStyle( | |
| color: widget.post.isAlert() == false ? Color(vestterColorBlackCyan) : Color(0xFFff681e), | |
| fontWeight: widget.post.isAlert() == false ? FontWeight.normal : FontWeight.bold, | |
| fontSize: 18), | |
| ), | |
| ), | |
| ), | |
| _buildAlertMarker(context, widget.post), | |
| SizedBox(width: 4), | |
| widget.post.user == widget.user.pk | |
| ? InkWell( | |
| onTap: () { | |
| _showModal(context, widget.post); | |
| }, | |
| child: Icon(Icons.more_horiz), | |
| ) | |
| : Container() | |
| ], | |
| ), | |
| Row( | |
| mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
| children: <Widget>[ | |
| Row( | |
| children: <Widget>[ | |
| Icon( | |
| Icons.navigation, | |
| size: MediaQuery.of(context).size.width * .04, | |
| color: Color(vestterColorBlackCyan).withOpacity(0.5), | |
| ), | |
| SizedBox(width: 4), | |
| Container( | |
| width: MediaQuery.of(context).size.width * 0.53, | |
| child: Text( | |
| widget.post.getLocationDescription(), | |
| softWrap: true, | |
| textAlign: TextAlign.left, | |
| style: TextStyle( | |
| color: Color(vestterColorBlackCyan).withOpacity(0.5), | |
| fontSize: Util.getProportionScreenWidth( | |
| context, | |
| 0.028, | |
| )), | |
| ), | |
| ), | |
| ], | |
| ), | |
| Expanded( | |
| child: Row( | |
| mainAxisAlignment: MainAxisAlignment.end, | |
| children: <Widget>[ | |
| Text( | |
| calcularTempoPostagem(widget.post.date), | |
| textAlign: TextAlign.right, | |
| style: TextStyle( | |
| color: Color(vestterColorBlackCyan).withOpacity(0.5), | |
| ), | |
| ), | |
| SizedBox(width: 4), | |
| Image.asset( | |
| 'assets/images/tab-checkin.png', | |
| width: 12, | |
| color: Color(vestterColorBlackCyan).withOpacity(0.5), | |
| ), | |
| ], | |
| ), | |
| ), | |
| ], | |
| ) | |
| ], | |
| ), | |
| ), | |
| ], | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment