Advertisement
Guest User

Untitled

a guest
Aug 18th, 2022
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 11.41 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_svg/svg.dart';
  3. import 'package:mugalim/core/const/text_style_const.dart';
  4. import 'package:mugalim/core/widgets/line_widget.dart';
  5. import 'package:mugalim/presentation/home/screens/home_comments.dart';
  6. import 'package:mugalim/presentation/home/widgets/SizedBox.dart';
  7. import 'package:mugalim/presentation/home/widgets/vote_widget.dart';
  8.  
  9. class PostWidget extends StatefulWidget {
  10.   final String postAuthor;
  11.   final String postPublicationDate;
  12.   final String title;
  13.   final String imageAuthor;
  14.  
  15.   final bool hasImg;
  16.   final String image;
  17.  
  18.   // All info about Vote
  19.   final bool hasVote;
  20.   final String votetitle;
  21.   final String voteAnswer1;
  22.   final String voteAnswer2;
  23.   final int votePPL1;
  24.   final int votePPL2;
  25.   final int voteProcent1;
  26.   final int voteProcent2;
  27.  
  28.   const PostWidget({
  29.     Key? key,
  30.     required this.title,
  31.     required this.postPublicationDate,
  32.     required this.postAuthor,
  33.     required this.imageAuthor,
  34.  
  35.     // All info about image
  36.     required this.hasImg,
  37.     required this.image,
  38.  
  39.     // All info about Vote
  40.     required this.hasVote,
  41.     required this.voteAnswer1,
  42.     required this.voteAnswer2,
  43.     required this.votePPL1,
  44.     required this.votePPL2,
  45.     required this.voteProcent1,
  46.     required this.voteProcent2,
  47.     required this.votetitle,
  48.   }) : super(key: key);
  49.  
  50.   @override
  51.   State<PostWidget> createState() => _PostWidgetState();
  52. }
  53.  
  54. class _PostWidgetState extends State<PostWidget> {
  55.   bool click_to_show = false;
  56.   String gonna = "";
  57.   bool isExpanded = false;
  58.   @override
  59.   Widget build(BuildContext context) {
  60.     return InkWell(
  61.       onTap: () {
  62.         Navigator.push(
  63.           context,
  64.           MaterialPageRoute(builder: (context) => HomeCommentsPage()),
  65.         );
  66.       },
  67.       child: Container(
  68.         decoration: const BoxDecoration(
  69.           color: Colors.white,
  70.           borderRadius: BorderRadius.all(Radius.circular(16)),
  71.         ),
  72.         child: Column(
  73.           children: [
  74.             Container(
  75.               padding: const EdgeInsets.only(
  76.                 left: 16,
  77.                 right: 16,
  78.                 top: 16,
  79.               ),
  80.               child: Column(
  81.                 children: [
  82.                   Row(
  83.                     children: [
  84.                       CircleAvatar(
  85.                         child: Image.asset(
  86.                           widget.imageAuthor,
  87.                           width: 44,
  88.                           height: 44,
  89.                         ),
  90.                       ),
  91.                       sizedBoxWidth16(),
  92.                       Column(
  93.                         crossAxisAlignment: CrossAxisAlignment.start,
  94.                         mainAxisAlignment: MainAxisAlignment.start,
  95.                         children: [
  96.                           Text(
  97.                             widget.postAuthor,
  98.                             style: TextStyles.mediumStyle.copyWith(
  99.                               color: const Color(0xFF1A1A1A),
  100.                               fontSize: 14,
  101.                               height: 1.4,
  102.                             ),
  103.                           ),
  104.                           Text(
  105.                             widget.postPublicationDate,
  106.                             style: TextStyles.regularStyle.copyWith(
  107.                               color: const Color(0xff767676),
  108.                             ),
  109.                           ),
  110.                         ],
  111.                       ),
  112.                       const Spacer(),
  113.                       IconButton(
  114.                         onPressed: () {},
  115.                         icon: const Icon(
  116.                           Icons.more_horiz,
  117.                           size: 28,
  118.                           color: Color(0xFF767676),
  119.                         ),
  120.                       ),
  121.                     ],
  122.                   ),
  123.                   sizedBoxHeight16(),
  124.  
  125.                   Align(
  126.                     alignment: Alignment.topLeft,
  127.                     child: Text(
  128.                       widget.title,
  129.                       style: TextStyles.regularStyle.copyWith(
  130.                         color: const Color(0xFF1A1A1A),
  131.                       ),
  132.                       maxLines: isExpanded ? 11 : 4,
  133.                       softWrap: true,
  134.                       // overflow: TextOverflow.fade,
  135.                     ),
  136.                   ),
  137.                   const SizedBox(
  138.                     height: 4,
  139.                   ),
  140.                   widget.title.length < 197
  141.                       ? SizedBox()
  142.                       : InkWell(
  143.                           onTap: () {
  144.                             setState(() {
  145.                               isExpanded = !isExpanded;
  146.                             });
  147.                           },
  148.                           child: Align(
  149.                             alignment: Alignment.topLeft,
  150.                             child: Text(
  151.                               isExpanded == false
  152.                                   ? 'Показать полностью...'
  153.                                   : 'Show less',
  154.                               style: TextStyles.mediumStyle.copyWith(
  155.                                 fontSize: 14,
  156.                                 color: const Color(0xff3D3DD8),
  157.                               ),
  158.                               maxLines: 1,
  159.                             ),
  160.                           ),
  161.                         ),
  162.  
  163.                   sizedBoxHeight8(),
  164.                   Visibility(
  165.                     visible: widget.hasVote,
  166.                     child: Column(
  167.                       children: [
  168.                         VoteWidget(
  169.                           votetitle: widget.votetitle,
  170.                           voteAnswer1: widget.voteAnswer1,
  171.                           voteAnswer2: widget.voteAnswer2,
  172.                           voteProcent1: widget.voteProcent1,
  173.                           voteProcent2: widget.voteProcent2,
  174.                           votePPL1: widget.votePPL1,
  175.                           votePPL2: widget.votePPL2,
  176.                         ),
  177.                         sizedBoxHeight8(),
  178.                       ],
  179.                     ),
  180.                   ),
  181.                 ],
  182.               ),
  183.             ),
  184.             Visibility(
  185.               visible: widget.hasImg,
  186.               child: Image.asset(
  187.                 widget.image,
  188.                 fit: BoxFit.cover,
  189.                 width: MediaQuery.of(context).size.width,
  190.               ),
  191.             ),
  192.             Container(
  193.               padding: const EdgeInsets.only(
  194.                 left: 16,
  195.                 right: 16,
  196.                 // top: 16,
  197.               ),
  198.               child: Column(
  199.                 children: [
  200.                   sizedBoxHeight8(),
  201.                   const LineWidget(),
  202.                   sizedBoxHeight8(),
  203.                   Row(
  204.                     children: [
  205.                       Container(
  206.                         width: 45,
  207.                         height: 28,
  208.                         decoration: BoxDecoration(
  209.                           color: const Color(0xffF9F9F9),
  210.                           borderRadius: BorderRadius.circular(24),
  211.                         ),
  212.                         child: Row(
  213.                           crossAxisAlignment: CrossAxisAlignment.center,
  214.                           mainAxisAlignment: MainAxisAlignment.center,
  215.                           children: [
  216.                             SvgPicture.asset(
  217.                               'assets/icons/heart.svg',
  218.                               color: const Color(0xff767676),
  219.                             ),
  220.                             const SizedBox(
  221.                               width: 5,
  222.                             ),
  223.                             const Text(
  224.                               '0',
  225.                               style: TextStyle(
  226.                                 color: Color(0xff767676),
  227.                               ),
  228.                             ),
  229.                           ],
  230.                         ),
  231.                       ),
  232.                       sizedBoxWidth8(),
  233.                       Container(
  234.                         width: 45,
  235.                         height: 28,
  236.                         decoration: BoxDecoration(
  237.                           color: const Color(0xffF9F9F9),
  238.                           borderRadius: BorderRadius.circular(24),
  239.                         ),
  240.                         child: Row(
  241.                           crossAxisAlignment: CrossAxisAlignment.center,
  242.                           mainAxisAlignment: MainAxisAlignment.center,
  243.                           children: [
  244.                             SvgPicture.asset(
  245.                               'assets/icons/comment.svg',
  246.                               color: const Color(0xff767676),
  247.                             ),
  248.                             const SizedBox(
  249.                               width: 5,
  250.                             ),
  251.                             const Text(
  252.                               '0',
  253.                               style: TextStyle(
  254.                                 color: Color(0xff767676),
  255.                               ),
  256.                             ),
  257.                           ],
  258.                         ),
  259.                       ),
  260.                       sizedBoxWidth8(),
  261.                       Container(
  262.                         width: 45,
  263.                         height: 28,
  264.                         decoration: BoxDecoration(
  265.                           color: const Color(0xffF9F9F9),
  266.                           borderRadius: BorderRadius.circular(24),
  267.                         ),
  268.                         child: Row(
  269.                           crossAxisAlignment: CrossAxisAlignment.center,
  270.                           mainAxisAlignment: MainAxisAlignment.center,
  271.                           children: [
  272.                             SvgPicture.asset(
  273.                               'assets/icons/share.svg',
  274.                               color: const Color(0xff767676),
  275.                             ),
  276.                             const SizedBox(
  277.                               width: 5,
  278.                             ),
  279.                             const Text(
  280.                               '0',
  281.                               style: TextStyle(
  282.                                 color: Color(0xff767676),
  283.                               ),
  284.                             ),
  285.                           ],
  286.                         ),
  287.                       ),
  288.                       const Spacer(),
  289.                       Row(
  290.                         crossAxisAlignment: CrossAxisAlignment.center,
  291.                         mainAxisAlignment: MainAxisAlignment.center,
  292.                         children: [
  293.                           SvgPicture.asset(
  294.                             'assets/icons/eyeIcon.svg',
  295.                           ),
  296.                           const SizedBox(
  297.                             width: 5,
  298.                           ),
  299.                           const Text(
  300.                             '2',
  301.                             style: TextStyle(
  302.                               color: Color(0xff767676),
  303.                             ),
  304.                           ),
  305.                         ],
  306.                       ),
  307.                     ],
  308.                   ),
  309.                   sizedBoxHeight16(),
  310.                 ],
  311.               ),
  312.             ),
  313.           ],
  314.         ),
  315.       ),
  316.     );
  317.   }
  318. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement