index_page.dart 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_note/views/cartpage/cart_page.dart';
  4. import 'package:flutter_note/views/category_page.dart';
  5. import 'package:flutter_note/views/homepage/home_page.dart';
  6. import 'package:flutter_note/views/mempage/mem_page.dart';
  7. import 'package:flutter_note/provide/page_index_provide.dart';
  8. import 'package:provide/provide.dart';
  9. class IndexPage extends StatelessWidget {
  10. @override
  11. Widget build(BuildContext context) {
  12. final _bottomTabs = <BottomNavigationBarItem>[
  13. BottomNavigationBarItem(
  14. icon: Icon(CupertinoIcons.home), title: Text('首页')),
  15. BottomNavigationBarItem(
  16. icon: Icon(CupertinoIcons.search), title: Text('分类')),
  17. BottomNavigationBarItem(
  18. icon: Icon(CupertinoIcons.shopping_cart), title: Text('购物车')),
  19. BottomNavigationBarItem(
  20. icon: Icon(CupertinoIcons.profile_circled), title: Text('会员中心'))
  21. ];
  22. final _tabPages = <Widget>[
  23. HomePage(),
  24. CategoryPage(),
  25. CartPage(),
  26. MemPage()
  27. ];
  28. return Provide<PageIndexProvide>(
  29. builder: (_, child, pageProvide) => Scaffold(
  30. backgroundColor: Color.fromRGBO(244, 245, 245, 1.0),
  31. body: IndexedStack(index: pageProvide.page, children: _tabPages),
  32. bottomNavigationBar: BottomNavigationBar(
  33. items: _bottomTabs,
  34. type: BottomNavigationBarType.fixed,
  35. currentIndex: pageProvide.page,
  36. onTap: (value) {
  37. Provide.value<PageIndexProvide>(context).changePage(value);
  38. },
  39. ),
  40. ));
  41. }
  42. }