details_page.dart 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_note/views/deatilspage/goods_comments.dart';
  4. import 'package:flutter_note/views/deatilspage/goods_detail.dart';
  5. import 'package:flutter_note/views/deatilspage/goods_handler.dart';
  6. import 'package:flutter_note/views/deatilspage/sliver_header_bar.dart';
  7. import 'package:flutter_note/provide/goods_detail_provide.dart';
  8. import 'package:provide/provide.dart';
  9. class DetailsPage extends StatelessWidget {
  10. final String goodsId;
  11. final _tabs = ['详情', '评论'];
  12. DetailsPage({Key key, this.goodsId}) : super(key: key);
  13. @override
  14. Widget build(BuildContext context) {
  15. Provide.value<GoodsDetailProvide>(context)
  16. ..changeDetails(goodsId)
  17. ..changeIndex(0);
  18. return Provide<GoodsDetailProvide>(builder: (_, widget, detailProvide) {
  19. var _detail = detailProvide.detail;
  20. return Scaffold(
  21. body: Container(
  22. alignment: Alignment.center,
  23. child: _detail == null ||
  24. _detail.data == null ||
  25. _detail.data.goodInfo == null
  26. ? CupertinoActivityIndicator(radius: 12.0) // 无商品情况使用加载
  27. // 使用横向滑动列表展示不同页面
  28. : DefaultTabController(
  29. length: _tabs.length,
  30. child: NestedScrollView(
  31. headerSliverBuilder: (context, innerScrolled) => [
  32. SliverOverlapAbsorber(
  33. handle:
  34. NestedScrollView.sliverOverlapAbsorberHandleFor(
  35. context),
  36. child: SliverHeaderBar(
  37. detailProvide: detailProvide,
  38. tabs: _tabs,
  39. innerScrolled: innerScrolled),
  40. )
  41. ],
  42. // 详情页面和评论页面列表
  43. body: TabBarView(
  44. children: [
  45. GoodsDetail(detailProvide: detailProvide),
  46. GoodsComments(detailProvide: detailProvide)
  47. ],
  48. ),
  49. ),
  50. ),
  51. ),
  52. bottomNavigationBar: GoodsHandler(detailProvide: detailProvide),
  53. );
  54. });
  55. }
  56. }