项目作者: f3l1x98

项目描述 :
Naviagtion panel and indicator for Flutter PageView
高级语言: Dart
项目地址: git://github.com/f3l1x98/pageview_navigation_panel.git
创建时间: 2020-08-06T13:52:45Z
项目社区:https://github.com/f3l1x98/pageview_navigation_panel

开源协议:MIT License

下载


pageview_navigation_panel

Widget for displaying the current page of a PageView and navigating said PageView using buttons.

Example

  1. import 'package:flutter/material.dart';
  2. import 'package:pageview_navigation_panel/pageview_navigation_panel.dart';
  3. class HomePage extends StatefulWidget {
  4. @override
  5. State<HomePage> createState() => new _HomePageState();
  6. }
  7. class HomePage extends StatefulWidget {
  8. @override
  9. State<HomePage> createState() => new _HomePageState();
  10. }
  11. class _HomePageState extends State<HomePage> {
  12. final PageController _pageController = new PageController(initialPage: 0);
  13. final _currentPageNotifier = ValueNotifier<double>(0.0);
  14. @override
  15. void initState() {
  16. super.initState();
  17. _pageController.addListener(() {
  18. _currentPageNotifier.value = _pageController.page;
  19. });
  20. }
  21. Widget _buildNavigationItem(String text, IconData icon) {
  22. return Column(
  23. children: [
  24. Icon(icon),
  25. Text('$text', style: Theme.of(context).textTheme.button.copyWith(fontSize: 16, fontWeight: FontWeight.bold),),
  26. ],
  27. );
  28. }
  29. Widget _buildViewWidget(String text) {
  30. return Center(
  31. child: Text('$text'),
  32. );
  33. }
  34. @override
  35. Widget build(BuildContext context) {
  36. return Scaffold(
  37. appBar: AppBar(
  38. title: Text('Example'),
  39. ),
  40. backgroundColor: Theme.of(context).backgroundColor,
  41. body: SafeArea(
  42. child: SizedBox(
  43. height: MediaQuery.of(context).size.height - 50,
  44. child: Column(
  45. children: [
  46. Container(
  47. height: MediaQuery.of(context).size.height - 180,
  48. child: PageView(
  49. controller: _pageController,
  50. children: [
  51. _buildViewWidget("View Widget 1"),
  52. _buildViewWidget("View Widget 2"),
  53. _buildViewWidget("View Widget 3"),
  54. _buildViewWidget("View Widget 4"),
  55. ],
  56. ),
  57. ),
  58. NavigationPanel(
  59. currentPageNotifier: _currentPageNotifier,
  60. pageController: _pageController,
  61. panelHeight: 100,
  62. buttonWidth: 80.0,
  63. buttonHeight: 60.0,
  64. indicatorColor: Theme.of(context).selectedRowColor,
  65. buttonChildren: [
  66. _buildNavigationItem('View1', Icons.looks_one),
  67. _buildNavigationItem('View2', Icons.looks_two),
  68. _buildNavigationItem('View3', Icons.looks_3),
  69. _buildNavigationItem('View4', Icons.looks_4),
  70. ],
  71. ),
  72. ],
  73. ),
  74. ),
  75. ),
  76. );
  77. }
  78. }