Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.04 KB | None | 0 0
  1. import 'dart:math';
  2.  
  3. import 'package:flutter/material.dart';
  4.  
  5. void main() {
  6.   runApp(MaterialApp(
  7.       home: Scaffold(
  8.     appBar: AppBar(
  9.       title: Text("SabaTest"),
  10.     ),
  11.     body: IndicatorPager(),
  12.   )));
  13. }
  14.  
  15. class IndicatorPager extends StatefulWidget {
  16.   @override
  17.   _IndicatorPagerState createState() => _IndicatorPagerState();
  18. }
  19.  
  20. class _IndicatorPagerState extends State<IndicatorPager> {
  21.   final List<Widget> _numbers = List.generate(10, _generatePages);
  22.   int _currentPage = 0;
  23.  
  24.   @override
  25.   Widget build(BuildContext context) {
  26.     return Stack(
  27.       children: <Widget>[
  28.         Padding(
  29.           padding: const EdgeInsets.all(16.0),
  30.           child: ProgressWidget(_currentPage, _numbers.length),
  31.         ),
  32.         PageView(
  33.           onPageChanged: (newPage) => setState(() {
  34.                 _currentPage = newPage;
  35.               }),
  36.           children: _numbers,
  37.         ),
  38.       ],
  39.     );
  40.   }
  41. }
  42.  
  43. Widget _generatePages(int index) {
  44.   return Center(child: Text(index.toString()));
  45. }
  46.  
  47. class ProgressWidget extends StatelessWidget {
  48.   final int _progress;
  49.   final int _total;
  50.  
  51.   const ProgressWidget(this._progress, this._total, {Key key})
  52.       : super(key: key);
  53.  
  54.   @override
  55.   Widget build(BuildContext context) {
  56.     return Row(
  57.       children: _getProgress(context),
  58.     );
  59.   }
  60.  
  61.   List<Widget> _getProgress(context) {
  62.     List<Widget> list = [];
  63.     for (int i = 0; i < _total; i++) {
  64.       list.add(Flexible(
  65.         flex: 5,
  66.         child: Container(
  67.           height: 5,
  68.           decoration: BoxDecoration(
  69.               color: i < _progress
  70.                   ? Theme.of(context).accentColor
  71.                   : Colors.grey[100],
  72.               borderRadius: BorderRadius.circular(20),
  73.               boxShadow: <BoxShadow>[
  74.                 BoxShadow(
  75.                   offset: Offset(1, 1),
  76.                   blurRadius: 3.0,
  77.                 )
  78.               ]),
  79.         ),
  80.       ));
  81.  
  82.       if (i < _total - 1) {
  83.         list.add(Spacer());
  84.       }
  85.     }
  86.     return list;
  87.   }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement