top_nativator.dart 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_note/model/home_page_model.dart';
  3. import 'package:flutter_note/provide/page_index_provide.dart';
  4. import 'package:provide/provide.dart';
  5. class TopNavigatorBar extends StatelessWidget {
  6. final List<Category> categories;
  7. TopNavigatorBar({Key key, @required this.categories}) : super(key: key);
  8. Widget _buildCategoryItem(BuildContext context, Category item) {
  9. return InkWell(
  10. onTap: () {
  11. Provide.value<PageIndexProvide>(context).changePage(1);
  12. },
  13. child: Column(
  14. mainAxisAlignment: MainAxisAlignment.center,
  15. children: [
  16. Image.network(item.image,
  17. width: MediaQuery.of(context).size.width / 8),
  18. Padding(
  19. padding: const EdgeInsets.only(top: 4.0),
  20. child: Text(item.mallCategoryName,
  21. style: TextStyle(color: Colors.black)),
  22. ),
  23. ],
  24. ),
  25. );
  26. }
  27. @override
  28. Widget build(BuildContext context) {
  29. if (categories.length > 10) categories.removeRange(10, categories.length);
  30. return SliverToBoxAdapter(
  31. child: SizedBox(
  32. height: MediaQuery.of(context).size.width * 2 / 5,
  33. child: GridView.count(
  34. padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
  35. childAspectRatio: 1.0,
  36. physics: NeverScrollableScrollPhysics(),
  37. crossAxisCount: 5,
  38. children: categories
  39. .map((item) => _buildCategoryItem(context, item))
  40. .toList(),
  41. ),
  42. ),
  43. );
  44. }
  45. }