Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.55 KB | None | 0 0
  1. import 'package:Pax/services/loggedUser.dart';
  2. import 'package:flutter/material.dart';
  3.  
  4. class DrawerHead extends StatelessWidget {
  5. final nameRegex = RegExp(r'(^[\wÀ-Ÿ]+).* ([\wÀ-Ÿ]+$)');
  6. final String img, name;
  7. final double qntStars;
  8. final PageController controller;
  9. final loggedUser = LoggedUser();
  10.  
  11. DrawerHead(this.img, this.name, this.qntStars, this.controller);
  12.  
  13. Color colorOfSidebarItem(BuildContext context) {
  14. return controller.page.round() == 1
  15. ? Theme.of(context).accentColor
  16. : Colors.grey;
  17. }
  18.  
  19. @override
  20. Widget build(BuildContext context) {
  21. return Column(
  22. children: <Widget>[
  23. Container(
  24. height: 56,
  25. color: Theme.of(context).primaryColor,
  26. child: Row(
  27. mainAxisAlignment: MainAxisAlignment.center,
  28. children: <Widget>[
  29. Image.asset(
  30. 'assets/logo/sidebar_logo.png',
  31. height: 30,
  32. ),
  33. ],
  34. ),
  35. ),
  36. Material(
  37. child: InkWell(
  38. onTap: () {
  39. Navigator.of(context).pop();
  40. controller.jumpToPage(1);
  41. },
  42. child: SizedBox(
  43. height: 130,
  44. child: Container(
  45. padding:
  46. const EdgeInsets.symmetric(vertical: 0, horizontal: 16),
  47. child: Row(
  48. children: <Widget>[
  49. Container(
  50. height: 70,
  51. width: 70,
  52. decoration: BoxDecoration(
  53. color: Colors.white,
  54. borderRadius: BorderRadius.all(Radius.circular(50.0)),
  55. border: Border.all(
  56. color: Theme.of(context).accentColor,
  57. width: 3.0,
  58. ),
  59. ),
  60. child: ClipOval(
  61. child: loggedUser.photo != null &&
  62. loggedUser.photo.isNotEmpty
  63. ? FadeInImage.assetNetwork(
  64. fit: BoxFit.cover,
  65. placeholder: 'assets/gifs/spinner.gif',
  66. image: loggedUser.photo,
  67. )
  68. : Image.asset('assets/user-img/default.png'),
  69. ),
  70. ),
  71. SizedBox(width: 16.0),
  72. Column(
  73. crossAxisAlignment: CrossAxisAlignment.start,
  74. mainAxisAlignment: MainAxisAlignment.center,
  75. children: <Widget>[
  76. Padding(
  77. padding: const EdgeInsets.only(left: 3),
  78. child: Text(
  79. "${nameRegex.firstMatch(name).group(1)} ${nameRegex.firstMatch(name).group(2)}",
  80. style: Theme.of(context).textTheme.headline,
  81. ),
  82. ),
  83. // SizedBox(height: 4),
  84. getUserStars(qntStars, context),
  85. SizedBox(height: 8),
  86. Padding(
  87. padding: const EdgeInsets.only(left: 4),
  88. child: Text(
  89. 'Ver meu Perfil',
  90. style: Theme.of(context)
  91. .textTheme
  92. .subtitle
  93. .copyWith(color: colorOfSidebarItem(context)),
  94. ),
  95. )
  96. ],
  97. )
  98. ],
  99. ),
  100. ),
  101. ),
  102. ),
  103. )
  104. ],
  105. );
  106. }
  107. }
  108.  
  109. Widget getUserStars(double n, BuildContext context) {
  110. List<Widget> list = new List<Widget>();
  111. int qntEl = n != null ? n.toInt() : 0;
  112. for (int i = 1; i <= 5; i++) {
  113. if (i <= qntEl)
  114. list.add(IconTheme(
  115. child: Icon(Icons.star),
  116. data: IconThemeData(color: Theme.of(context).accentColor),
  117. ));
  118. else
  119. list.add(IconTheme(
  120. child: Icon(Icons.star_border),
  121. data: IconThemeData(color: Theme.of(context).accentColor),
  122. ));
  123. }
  124.  
  125. if ((n - qntEl) > 0) {
  126. list[qntEl.round()] = IconTheme(
  127. child: Icon(Icons.star_half),
  128. data: IconThemeData(color: Theme.of(context).accentColor),
  129. );
  130. }
  131. return Row(children: list);
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement