main.dart 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. import 'package:douyin_demo/pages/RecommendPage/BottomSheet.dart';
  2. import 'package:douyin_demo/providers/RecommendProvider.dart';
  3. import 'package:douyin_demo/widgets/BottomBar.dart';
  4. // import 'package:douyin_demo/widgets/FavAnimation.dart' as prefix0;
  5. import 'package:flutter/material.dart';
  6. // import 'package:marquee/marquee.dart';
  7. import 'package:marquee_flutter/marquee_flutter.dart';
  8. import 'package:provider/provider.dart';
  9. import 'package:video_player/video_player.dart';
  10. import 'widgets/FavAnimation.dart';
  11. void main() {
  12. runApp(MyApp());
  13. }
  14. class MyApp extends StatelessWidget {
  15. const MyApp({Key key}) : super(key: key);
  16. @override
  17. Widget build(BuildContext context) {
  18. return MaterialApp(
  19. title: "某音",
  20. theme: ThemeData(primaryColor: Color(0xff121319)),
  21. home: MultiProvider(
  22. providers: [
  23. ChangeNotifierProvider(
  24. builder: (context) => RecommendProvider(),
  25. )
  26. ],
  27. child: Scaffold(
  28. resizeToAvoidBottomInset: false,
  29. body: Container(
  30. decoration: BoxDecoration(color: Colors.black),
  31. child: Stack(children: [
  32. CenterImage(),
  33. Home(),
  34. ]),
  35. ),
  36. bottomNavigationBar: BottomSafeBar(),
  37. )),
  38. );
  39. }
  40. }
  41. class BottomSafeBar extends StatelessWidget {
  42. const BottomSafeBar({Key key}) : super(key: key);
  43. @override
  44. Widget build(BuildContext context) {
  45. RecommendProvider provider = Provider.of<RecommendProvider>(context);
  46. // double toBottom=MediaQuery.of(context).viewInsets.bottom;
  47. return Container(
  48. // padding: EdgeInsets.only(top:toBottom),
  49. decoration: BoxDecoration(color: Colors.black),
  50. child: SafeArea(
  51. child: BottomAppBar(
  52. child: Container(
  53. decoration: BoxDecoration(color: Colors.black),
  54. height: 60,
  55. // decoration: BoxDecoration(color: Colors.black),
  56. child: BtmBar(selectIndex: 0,),
  57. ),
  58. )),
  59. );
  60. }
  61. }
  62. class CenterImage extends StatelessWidget {
  63. const CenterImage({Key key}) : super(key: key);
  64. @override
  65. Widget build(BuildContext context) {
  66. double bottom = MediaQuery.of(context).viewInsets.bottom;
  67. RecommendProvider provider = Provider.of<RecommendProvider>(context);
  68. return Center(
  69. child: Container(
  70. // padding: EdgeInsets.only(top: bottom),
  71. child: Image.asset(provider.mainInfo.videoPath)),
  72. );
  73. }
  74. }
  75. class VideoBack extends StatefulWidget {
  76. VideoBack({Key key}) : super(key: key);
  77. _VideoBackState createState() => _VideoBackState();
  78. }
  79. class _VideoBackState extends State<VideoBack> {
  80. VideoPlayerController _controller;
  81. bool _isPlaying = false;
  82. String url =
  83. "https://www.guojio.com/video/07a7faa1-3696-4af7-aeac-2d6cf6bf25f9.mp4";
  84. @override
  85. void initState() {
  86. // TODO: implement initState
  87. super.initState();
  88. _controller = VideoPlayerController.network(this.url)
  89. // 播放状态
  90. ..addListener(() {
  91. final bool isPlaying = _controller.value.isPlaying;
  92. if (isPlaying != _isPlaying) {
  93. setState(() {
  94. _isPlaying = isPlaying;
  95. });
  96. }
  97. })
  98. // 在初始化完成后必须更新界面
  99. ..initialize().then((_) {
  100. setState(() {});
  101. });
  102. }
  103. @override
  104. Widget build(BuildContext context) {
  105. return Container(
  106. child: _controller.value.initialized
  107. // 加载成功
  108. ? new AspectRatio(
  109. aspectRatio: _controller.value.aspectRatio,
  110. child: VideoPlayer(_controller),
  111. )
  112. : new Container(),
  113. );
  114. }
  115. }
  116. class Home extends StatelessWidget {
  117. const Home({Key key}) : super(key: key);
  118. @override
  119. Widget build(BuildContext context) {
  120. double screenWidth = MediaQuery.of(context).size.width;
  121. double screenHeight = MediaQuery.of(context).size.height;
  122. RecommendProvider provider = Provider.of<RecommendProvider>(context);
  123. double rpx = screenWidth / 750;
  124. return Stack(children: [
  125. Positioned(
  126. top: 20*rpx,
  127. // height: 120,
  128. width: screenWidth,
  129. child: SafeArea(
  130. child: Container(
  131. // decoration: BoxDecoration(color: Colors.pinkAccent),
  132. child: TopTab(),
  133. )),
  134. ),
  135. Positioned(
  136. bottom: 0,
  137. width: 0.70 * screenWidth,
  138. height: 260 * rpx,
  139. child: Container(
  140. // decoration: BoxDecoration(color: Colors.redAccent),
  141. child: BtnContent(),
  142. ),
  143. ),
  144. Positioned(
  145. right: 0,
  146. width: 0.2 * screenWidth,
  147. height: 500 * rpx,
  148. top: 0.45 * screenHeight,
  149. child: Container(
  150. // decoration: BoxDecoration(color: Colors.orangeAccent),
  151. child: ButtonList(),
  152. ),
  153. ),
  154. Positioned(
  155. bottom: 20 * rpx,
  156. right: 0,
  157. width: 0.2 * screenWidth,
  158. height: 0.2 * screenWidth,
  159. child: Container(
  160. // decoration: BoxDecoration(color: Colors.purpleAccent),
  161. child: RotateAlbum(),
  162. ),
  163. )
  164. ]);
  165. }
  166. }
  167. class TopTab extends StatefulWidget {
  168. TopTab({Key key}) : super(key: key);
  169. _TopTabState createState() => _TopTabState();
  170. }
  171. class _TopTabState extends State<TopTab> with SingleTickerProviderStateMixin {
  172. TabController _controller;
  173. @override
  174. void initState() {
  175. // TODO: implement initState
  176. super.initState();
  177. _controller = TabController(vsync: this, length: 2, initialIndex: 1);
  178. }
  179. @override
  180. Widget build(BuildContext context) {
  181. double rpx = MediaQuery.of(context).size.width / 750;
  182. return Row(
  183. crossAxisAlignment: CrossAxisAlignment.center,
  184. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  185. children: [
  186. SizedBox(
  187. width: 17 * rpx,
  188. ),
  189. Icon(
  190. Icons.search,
  191. size: 50 * rpx,
  192. color: Colors.white,
  193. ),
  194. Container(
  195. child: Container(
  196. padding: EdgeInsets.symmetric(horizontal: 90 * rpx),
  197. width: 500 * rpx,
  198. child: TabBar(
  199. indicatorColor: Colors.white,
  200. labelStyle: TextStyle(color: Colors.white, fontSize: 20),
  201. indicatorPadding: EdgeInsets.symmetric(horizontal: 30),
  202. unselectedLabelStyle:
  203. TextStyle(color: Colors.grey[700], fontSize: 18),
  204. controller: _controller,
  205. tabs: <Widget>[Text("关注"), Text("推荐")],
  206. ))),
  207. Icon(
  208. Icons.live_tv,
  209. size: 30,
  210. color: Colors.white,
  211. ),
  212. SizedBox(
  213. width: 10,
  214. ),
  215. ],
  216. );
  217. }
  218. }
  219. class BtnContent extends StatelessWidget {
  220. const BtnContent({Key key}) : super(key: key);
  221. @override
  222. Widget build(BuildContext context) {
  223. RecommendProvider provider = Provider.of<RecommendProvider>(context);
  224. return Container(
  225. child: Column(
  226. mainAxisSize: MainAxisSize.min,
  227. children: <Widget>[
  228. ListTile(
  229. title: Text(
  230. "@${provider.mainInfo.userName}",
  231. style: TextStyle(color: Colors.white, fontSize: 16),
  232. ),
  233. subtitle: Text(
  234. "${provider.mainInfo.content}",
  235. style: TextStyle(color: Colors.white, fontSize: 16),
  236. maxLines: 3,
  237. overflow: TextOverflow.ellipsis,
  238. ),
  239. ),
  240. Row(
  241. children: <Widget>[
  242. SizedBox(
  243. width: 10,
  244. ),
  245. Icon(
  246. Icons.music_note,
  247. color: Colors.white,
  248. ),
  249. // Marquee(text: "",),
  250. // Container(
  251. // width: 200,
  252. // height: 20,
  253. // child: MarqueeWidget(
  254. // text: '${provider.mainInfo.desc}',
  255. // textStyle: TextStyle(
  256. // fontWeight: FontWeight.bold,
  257. // color: Colors.white,
  258. // fontSize: 16),
  259. // // scrollAxis: Axis.horizontal,
  260. // // crossAxisAlignment: CrossAxisAlignment.start,
  261. // // blankSpace: 20.0,
  262. // // velocity: 100.0,
  263. // // pauseAfterRound: Duration(seconds: 1),
  264. // // startPadding: 10.0,
  265. // // accelerationDuration: Duration(seconds: 1),
  266. // // accelerationCurve: Curves.linear,
  267. // // decelerationDuration: Duration(milliseconds: 500),
  268. // // decelerationCurve: Curves.easeOut,
  269. // ))
  270. ],
  271. )
  272. ],
  273. ),
  274. );
  275. }
  276. }
  277. class RotateAlbum extends StatefulWidget {
  278. RotateAlbum({Key key}) : super(key: key);
  279. _RotateAlbumState createState() => _RotateAlbumState();
  280. }
  281. class _RotateAlbumState extends State<RotateAlbum>
  282. with SingleTickerProviderStateMixin {
  283. AnimationController _controller;
  284. var animation;
  285. @override
  286. void initState() {
  287. super.initState();
  288. _controller =
  289. AnimationController(vsync: this, duration: Duration(seconds: 4));
  290. animation = RotationTransition(
  291. turns: Tween(begin: 0.0, end: 1.0).animate(_controller)
  292. ..addStatusListener((status) {
  293. if (status == AnimationStatus.completed) {
  294. _controller.forward(from: 0.0);
  295. }
  296. }),
  297. child: Container(
  298. child: CircleAvatar(
  299. backgroundImage: NetworkImage(
  300. "https://gss1.bdstatic.com/9vo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D500/sign=dde475320ee9390152028d3e4bec54f9/d009b3de9c82d1586d8294a38f0a19d8bc3e42a4.jpg"),
  301. )),
  302. );
  303. _controller.forward(from: 0.0);
  304. }
  305. @override
  306. Widget build(BuildContext context) {
  307. return Container(
  308. padding: EdgeInsets.all(18),
  309. child: animation,
  310. );
  311. }
  312. }
  313. class ButtonList extends StatefulWidget {
  314. ButtonList({Key key}) : super(key: key);
  315. _ButtonListState createState() => _ButtonListState();
  316. }
  317. class _ButtonListState extends State<ButtonList> {
  318. @override
  319. Widget build(BuildContext context) {
  320. double rpx = MediaQuery.of(context).size.width / 750;
  321. RecommendProvider provider = Provider.of<RecommendProvider>(context);
  322. List<IconAnimationStage> stages1 = List<IconAnimationStage>();
  323. stages1.add(IconAnimationStage(
  324. color: Colors.grey[100],
  325. start: 1.0,
  326. end: 0.0,
  327. duration: Duration(milliseconds: 200)));
  328. stages1.add(IconAnimationStage(
  329. color: Colors.redAccent,
  330. start: 0.0,
  331. end: 1.3,
  332. duration: Duration(milliseconds: 300)));
  333. stages1.add(IconAnimationStage(
  334. color: Colors.redAccent,
  335. start: 1.3,
  336. end: 1.0,
  337. duration: Duration(milliseconds: 100)));
  338. List<IconAnimationStage> stages2 = List<IconAnimationStage>();
  339. stages2.add(IconAnimationStage(
  340. color: Colors.grey[100],
  341. start: 1.0,
  342. end: 1.2,
  343. duration: Duration(milliseconds: 200)));
  344. stages2.add(IconAnimationStage(
  345. color: Colors.grey[100],
  346. start: 1.2,
  347. end: 1.0,
  348. duration: Duration(milliseconds: 200)));
  349. List<IconAnimationStage> stages3 = List<IconAnimationStage>();
  350. stages3.add(IconAnimationStage(
  351. color: Colors.redAccent,
  352. start: 1.0,
  353. end: 1.2,
  354. duration: Duration(milliseconds: 200)));
  355. stages3.add(IconAnimationStage(
  356. color: Colors.grey[100],
  357. start: 1.2,
  358. end: 1.0,
  359. duration: Duration(milliseconds: 200)));
  360. double iconSize = 70 * rpx;
  361. return Container(
  362. child: Column(
  363. mainAxisAlignment: MainAxisAlignment.spaceAround,
  364. crossAxisAlignment: CrossAxisAlignment.center,
  365. children: <Widget>[
  366. Container(
  367. width: 90 * rpx,
  368. height: 105 * rpx,
  369. child: Stack(
  370. children: <Widget>[
  371. Container(
  372. // decoration: BoxDecoration(c),
  373. width: 90 * rpx,
  374. height: 90 * rpx,
  375. child: CircleAvatar(
  376. backgroundImage:
  377. NetworkImage("${provider.mainInfo.avatarUrl}"),
  378. )),
  379. Positioned(
  380. bottom: 0,
  381. left: 25 * rpx,
  382. child: Container(
  383. width: 40 * rpx,
  384. height: 40 * rpx,
  385. decoration: BoxDecoration(
  386. color: Colors.redAccent,
  387. borderRadius: BorderRadius.circular(25)),
  388. child: Icon(
  389. Icons.add,
  390. size: 20,
  391. color: Colors.white,
  392. ),
  393. ),
  394. )
  395. ],
  396. )),
  397. IconText(
  398. text: "${provider.mainInfo.favCount}",
  399. icon: !provider.mainInfo.ifFaved
  400. ? AnimatedIconWidget(
  401. key: UniqueKey(),
  402. animationList: stages1,
  403. icon: Icons.favorite,
  404. size: iconSize,
  405. provider: provider,
  406. callback: () {
  407. provider.tapFav();
  408. })
  409. : AnimatedIconWidget(
  410. key: UniqueKey(),
  411. animationList: stages3,
  412. icon: Icons.favorite,
  413. size: iconSize,
  414. provider: provider,
  415. callback: () {
  416. provider.tapFav();
  417. },
  418. ),
  419. ),
  420. IconText(
  421. text: "${provider.mainInfo.replyCount}",
  422. icon: AnimatedIconWidget(
  423. animationList: stages2,
  424. icon: Icons.comment,
  425. size: iconSize,
  426. callbackDelay: Duration(milliseconds: 200),
  427. callback: () {
  428. showBottom(context, provider);
  429. },
  430. ),
  431. ),
  432. IconText(
  433. text: "${provider.mainInfo.shareCount}",
  434. icon: AnimatedIconWidget(
  435. animationList: stages2,
  436. icon: Icons.reply,
  437. size: iconSize,
  438. ),
  439. ),
  440. ],
  441. ),
  442. );
  443. }
  444. }
  445. // class ButtonList extends StatelessWidget {
  446. // const ButtonList({Key key}) : super(key: key);
  447. // @override
  448. // }
  449. // getButtonList(double rpx, RecommendProvider provider, BuildContext context) {
  450. // return
  451. // }
  452. class IconText extends StatelessWidget {
  453. const IconText({Key key, this.icon, this.text}) : super(key: key);
  454. final AnimatedIconWidget icon;
  455. final String text;
  456. @override
  457. Widget build(BuildContext context) {
  458. double rpx = MediaQuery.of(context).size.width / 750;
  459. return Container(
  460. child: Column(
  461. mainAxisSize: MainAxisSize.min,
  462. mainAxisAlignment: MainAxisAlignment.center,
  463. crossAxisAlignment: CrossAxisAlignment.center,
  464. children: <Widget>[
  465. icon,
  466. Container(
  467. // alignment: Alignment.center,
  468. child: Text(
  469. text,
  470. style: TextStyle(color: Colors.white, fontSize: 25 * rpx),
  471. )),
  472. ],
  473. ),
  474. );
  475. }
  476. }
  477. showBottom(context, provider) {
  478. // RecommendProvider provider = Provider.of<RecommendProvider>(context);
  479. double height = MediaQuery.of(context).size.height;
  480. provider.setScreenHeight(height);
  481. provider.hideBottomBar();
  482. showModalBottomSheet(
  483. shape: RoundedRectangleBorder(
  484. borderRadius: BorderRadiusDirectional.circular(10)),
  485. context: context,
  486. builder: (_) {
  487. return Container(
  488. height: 600,
  489. child: GestureDetector(
  490. onTap: () {
  491. FocusScope.of(context).requestFocus(FocusNode());
  492. },
  493. child: ReplyFullList(pCtx:context)));
  494. });
  495. }