Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2021
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1. class SpecificLaunch extends StatefulWidget {
  2. final String heroTag;
  3.  
  4. SpecificLaunch({this.heroTag});
  5.  
  6. @override
  7. _SpecificLaunchState createState() => _SpecificLaunchState();
  8. }
  9.  
  10. class _SpecificLaunchState extends State<SpecificLaunch> {
  11. @override
  12. void dispose() {
  13. timer.cancel();
  14. super.dispose();
  15. }
  16.  
  17. static const duration = const Duration(seconds: 1);
  18.  
  19. int timeDiff = DateTime.parse(launchesObject.launchDate)
  20. .difference(DateTime.now())
  21. .inSeconds;
  22. bool isActive = true;
  23.  
  24. Timer timer;
  25.  
  26. @override
  27. Widget build(BuildContext context) {
  28. if (timer == null) {
  29. timer = Timer.periodic(duration, (Timer t) {
  30. if (timeDiff > 0) {
  31. setState(() {
  32. if (mounted) if (DateTime.parse(launchesObject.launchDate) !=
  33. DateTime.now()) {
  34. timeDiff -= 1;
  35. } else {
  36. print('Times up!');
  37. //Do something
  38. }
  39. });
  40. }
  41. });
  42. }
  43.  
  44. int days = timeDiff ~/ (24 * 60 * 60);
  45. int hours = timeDiff ~/ (60 * 60) % 24;
  46. int minutes = (timeDiff ~/ 60) % 60;
  47. int seconds = timeDiff % 60;
  48.  
  49. return DefaultTabController(
  50. length: 3,
  51. child: Scaffold(
  52. appBar: AppBar(
  53. title: Text(
  54. 'Launch',
  55. style: GoogleFonts.poppins(fontWeight: FontWeight.w600),
  56. ),
  57. actions: [
  58. IconButton(icon: Icon(Icons.share_outlined), onPressed: () {})
  59. ],
  60. ),
  61. body: Padding(
  62. padding: EdgeInsets.only(
  63. top: getHeight(context) / 30.0,
  64. left: getWidth(context) / 30.0,
  65. right: getWidth(context) / 30.0),
  66. child: Column(
  67. children: [
  68. Container(
  69. height: getHeight(context) / 3.5,
  70. width: getWidth(context),
  71. child: Card(
  72. shape: RoundedRectangleBorder(
  73. borderRadius:
  74. BorderRadius.circular(getWidth(context) / 36.0)),
  75. child: Stack(
  76. children: [
  77. Container(
  78. height: getHeight(context),
  79. width: getWidth(context),
  80. child: Hero(
  81. tag: widget.heroTag,
  82. child: CachedNetworkImage(
  83. imageUrl: launchesObject.launchImageUrl,
  84. fit: BoxFit.cover,
  85. placeholder: (context, url) {
  86. return Container();
  87. },
  88. ),
  89. ),
  90. ),
  91. Align(
  92. alignment: Alignment.bottomCenter,
  93. child: Container(
  94. height: getHeight(context) / 13.0,
  95. width: getWidth(context),
  96. color:
  97. SpecificColors(context).timerBackgroundColor,
  98. alignment: Alignment.center,
  99. child: Text(
  100. days.toString() +
  101. 'dd ' +
  102. hours.toString() +
  103. 'h ' +
  104. minutes.toString() +
  105. 'm ' +
  106. seconds.toString() +
  107. 's',
  108. style: GoogleFonts.poppins(
  109. fontWeight: FontWeight.w500,
  110. fontSize: 22,
  111. color:
  112. SpecificColors(context).timerTextColor),
  113. ),
  114. ),
  115. )
  116. ],
  117. ),
  118. ),
  119. ),
  120. Container(
  121. height: 70,
  122. child: AppBar(
  123. centerTitle: true,
  124. title: Text("New Titile"),
  125. bottom: TabBar(
  126. tabs: [
  127. Tab(
  128. text: 'State',
  129. ),
  130. Tab(
  131. text: 'Mission',
  132. ),
  133. Tab(
  134. text: 'Rocket',
  135. )
  136. ],
  137. ),
  138. ),
  139. ),
  140. Expanded(
  141. child: TabBarView(
  142. children: [
  143. Text(
  144. 'Tab 1',
  145. ),
  146. Text('Tab 2'),
  147. Text('Tab 3')
  148. ],
  149. ),
  150. )
  151. ],
  152. ),
  153. )),
  154. );
  155. }
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement