Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.47 KB | None | 0 0
  1. import 'package:app1551/ui/ticket_detail_page/ticket_detail_state.dart';
  2. import 'package:app1551/ui/ticket_detail_page/widgets/real_rich_text.dart';
  3. import 'package:app1551/utils/colors.dart';
  4. import 'package:flutter/gestures.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:redux/redux.dart';
  7.  
  8. class TicketDetailDescription extends StatelessWidget {
  9. final Store<TicketDetailState> store;
  10. final double height;
  11.  
  12. TicketDetailDescription(
  13. {Key key, Store<TicketDetailState> this.store, this.height})
  14. : super(key: key);
  15.  
  16. @override
  17. Widget build(BuildContext context) {
  18. var tp = TextPainter(
  19. text: TextSpan(
  20. text: TicketDetailState.ticket.description,
  21. style: TextStyle(
  22. fontSize: MediaQuery.of(context).size.width>320?13:11,
  23. color: Color.fromARGB(255, 72, 72, 70),
  24. fontFamily: Fonts.gothamPro,
  25. height: 1.5)),
  26. maxLines: 1,
  27. textDirection: TextDirection.ltr);
  28. tp.layout(maxWidth: MediaQuery.of(context).size.width - 32);
  29. var contentHeight = height - 250;
  30. var maxLines = contentHeight / tp.preferredLineHeight;
  31. maxLines = maxLines<1?1:maxLines;
  32. var tp2 = TextPainter(
  33. text: TextSpan(
  34. text: TicketDetailState.ticket.description,
  35. style: TextStyle(
  36. fontSize: MediaQuery.of(context).size.width>320?13:11,
  37. color: Color.fromARGB(255, 72, 72, 70),
  38. fontFamily: Fonts.gothamPro,
  39. height: 1.5)),
  40. maxLines: maxLines.toInt(),
  41. textDirection: TextDirection.ltr);
  42. tp2.layout(maxWidth: MediaQuery.of(context).size.width - 32);
  43.  
  44. var showBtn = tp2.didExceedMaxLines;
  45.  
  46. return Container(
  47. margin: EdgeInsets.only(bottom: 24),
  48. child: AnimatedCrossFade(
  49. duration: Duration(milliseconds: 200),
  50. crossFadeState: store.state.expandDescription
  51. ? CrossFadeState.showSecond
  52. : CrossFadeState.showFirst,
  53. firstChild: Stack(
  54. alignment: Alignment.bottomRight,
  55. children: <Widget>[
  56. RealRichText(
  57. [
  58. TextSpan(
  59. text: TicketDetailState.ticket.description,
  60. style: TextStyle(
  61. fontSize: MediaQuery.of(context).size.width>320?13:11,
  62. color: Color.fromARGB(255, 72, 72, 70),
  63. fontFamily: Fonts.gothamPro,
  64. height: 1.5)),
  65.  
  66. ],
  67. maxLines: maxLines.toInt(),
  68. ),
  69. if (showBtn)
  70. Container(
  71. decoration: BoxDecoration(
  72. gradient: LinearGradient(
  73. begin: Alignment.centerLeft,
  74. end: Alignment.centerRight,
  75. colors: [
  76. Colors.white.withOpacity(0),
  77. Col.white,
  78. Col.white
  79. ])),
  80. child: Padding(
  81. padding: const EdgeInsets.only(bottom: 0),
  82. child: GestureDetector(
  83. onTap: () {
  84. store.dispatch(TicketDetailActions.ToggleDescription);
  85. },
  86. child: RealRichText(
  87. [
  88. TextSpan(text: " "),
  89. TextSpan(
  90. text: showBtn ? 'Більше ' : "",
  91. style: TextStyle(
  92. fontSize: MediaQuery.of(context).size.width>320?13:11,
  93. color: Colors.deepPurple[300].withOpacity(0.7),
  94. fontFamily: Fonts.gothamPro,
  95. decoration: TextDecoration.underline),
  96. ),
  97. if (showBtn)
  98. ImageSpan(
  99. AssetImage("assets/icons/chevron_down.png"),
  100. imageHeight: 12,
  101. imageWidth: 12,
  102. )
  103. ],
  104. maxLines: maxLines.toInt(),
  105. ),
  106. ),
  107. ),
  108. )
  109. ],
  110. ),
  111. secondChild: RealRichText(
  112. [
  113. TextSpan(
  114. text: '${TicketDetailState.ticket.description} ',
  115. style: TextStyle(
  116. fontSize: MediaQuery.of(context).size.width>320?13:11,
  117. color: Color.fromARGB(255, 72, 72, 70),
  118. fontFamily: Fonts.gothamPro,
  119. height: 1.5)),
  120. TextSpan(
  121. text: 'Менше ',
  122. style: TextStyle(
  123. fontSize: MediaQuery.of(context).size.width>320?13:11,
  124. color: Colors.deepPurple[300].withOpacity(0.7),
  125. fontFamily: Fonts.gothamPro,
  126. decoration: TextDecoration.underline),
  127. recognizer: new TapGestureRecognizer()
  128. ..onTap = () {
  129. store.dispatch(TicketDetailActions.ToggleDescription);
  130. }),
  131. if (showBtn)
  132. ImageSpan(
  133. AssetImage("assets/icons/chevron_up.png"),
  134. imageHeight: 12,
  135. imageWidth: 12,
  136. )
  137. ],
  138. ),
  139. ),
  140. );
  141. }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement