bookshelf_header.dart 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import 'package:flutter/material.dart';
  2. import 'package:shuqi/public.dart';
  3. import 'bookshelf_cloud_widget.dart';
  4. class BookshelfHeader extends StatefulWidget {
  5. final Novel novel;
  6. BookshelfHeader(this.novel);
  7. @override
  8. _BookshelfHeaderState createState() => _BookshelfHeaderState();
  9. }
  10. class _BookshelfHeaderState extends State<BookshelfHeader> with SingleTickerProviderStateMixin {
  11. late AnimationController controller;
  12. late Animation<double> animation;
  13. @override
  14. initState() {
  15. super.initState();
  16. controller = AnimationController(duration: const Duration(milliseconds: 2000), vsync: this);
  17. animation = Tween(begin: 0.0, end: 1.0).animate(controller);
  18. animation.addStatusListener((status) {
  19. if (status == AnimationStatus.completed) {
  20. controller.reverse();
  21. } else if (status == AnimationStatus.dismissed) {
  22. controller.forward();
  23. }
  24. });
  25. controller.forward();
  26. }
  27. dispose() {
  28. controller.dispose();
  29. super.dispose();
  30. }
  31. @override
  32. Widget build(BuildContext context) {
  33. var width = Screen.width;
  34. var bgHeight = width / 0.9;
  35. var height = Screen.topSafeHeight + 250;
  36. return Container(
  37. width: width,
  38. height: height,
  39. child: Stack(
  40. children: <Widget>[
  41. Positioned(
  42. top: height - bgHeight,
  43. child: Image.asset(
  44. 'assets/img/bookshelf_bg.png',
  45. fit: BoxFit.cover,
  46. width: width,
  47. height: bgHeight,
  48. ),
  49. ),
  50. Positioned(
  51. bottom: 0,
  52. child: BookshelfCloudWidget(
  53. animation: animation,
  54. width: width,
  55. ),
  56. ),
  57. buildContent(context),
  58. ],
  59. ),
  60. );
  61. }
  62. Widget buildContent(BuildContext context) {
  63. Novel novel = this.widget.novel;
  64. var width = Screen.width;
  65. return Container(
  66. width: width,
  67. padding: EdgeInsets.fromLTRB(15, 54 + Screen.topSafeHeight, 10, 0),
  68. color: Colors.transparent,
  69. child: GestureDetector(
  70. onTap: () {
  71. AppNavigator.pushNovelDetail(context, novel);
  72. },
  73. child: Row(
  74. crossAxisAlignment: CrossAxisAlignment.start,
  75. children: <Widget>[
  76. DecoratedBox(
  77. child: NovelCoverImage(novel.imgUrl, width: 120, height: 160),
  78. decoration: BoxDecoration(boxShadow: Styles.borderShadow),
  79. ),
  80. SizedBox(width: 20),
  81. Expanded(
  82. child: Column(
  83. crossAxisAlignment: CrossAxisAlignment.start,
  84. children: <Widget>[
  85. SizedBox(height: 40),
  86. Text(novel.name, style: TextStyle(fontSize: 20, color: Colors.white, fontWeight: FontWeight.bold)),
  87. SizedBox(height: 20),
  88. Row(
  89. children: <Widget>[
  90. Text('读至0.2% 继续阅读 ', style: TextStyle(fontSize: 14, color: SQColor.paper)),
  91. Image.asset('assets/img/bookshelf_continue_read.png'),
  92. ],
  93. ),
  94. ],
  95. ),
  96. )
  97. ],
  98. ),
  99. ),
  100. );
  101. }
  102. }