Code Monkey home page Code Monkey logo

dots_indicator's Introduction

dots_indicator

Widget to display dots indicator to show a position (for a PageView for example).

Installation

You just need to add dots_indicator as a dependency in your pubspec.yaml file.

dependencies:
  dots_indicator: ^2.1.1

Example

In these examples, pageLength is the total of dots to display and currentIndexPage is the position to hightlight (the active dot).

A simple dots indicator

Simple dots

new DotsIndicator(
  dotsCount: pageLength,
  position: currentIndexPage,
);

Custom colors

Custom dots colors

new DotsIndicator(
  dotsCount: pageLength,
  position: currentIndexPage,
  decorator: DotsDecorator(
    color: Colors.black87, // Inactive color
    activeColor: Colors.redAccent,
  ),
);

Use specific color for each dot

You can choose to have one color for inactive dots and one color the active dot.

But you can also define one color by inactive dots (colors) and one color by active dot (activeColors).

If you have a total of 3 dots, you must provide an array of 3 colors.

new DotsIndicator(
  dotsCount: pageLength,
  position: currentIndexPage,
  decorator: DotsDecorator(
    colors: [Colors.grey[300], Colors.grey[600], Colors.grey[900]], // Inactive dot colors
    activeColors: [Colors.red[300], Colors.red[600], Colors.red[900]], // Àctive dot colors
  ),
);

Custom size and shape

You can change the default size of dots and also shape.

So you can choose to have a shape for inactive dots and another shape for the active dot for example.
By default, the shape of dots are CircleBorder, so to have a rounded rectangle for active one, you need to change activeShape

Custom dots size

new DotsIndicator(
  dotsCount: pageLength,
  position: currentIndexPage,
  decorator: DotsDecorator(
    size: const Size.square(9.0),
    activeSize: const Size(18.0, 9.0),
    activeShape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
  ),
);

Custom size for each dot

You can customize the size of each dot, for inactive and/or active dots.

For that, use sizes and/or activeSizes params.

new DotsIndicator(
  dotsCount: pageLength,
  position: currentIndexPage,
  decorator: DotsDecorator(
    sizes: [
      const Size.square(10.0),
      const Size.square(15.0),
      const Size.square(20.0),
    ],
    activeSizes: [
      const Size.square(25.0),
      const Size.square(25.0),
      const Size.square(35.0),
    ],
  ),
);

Custom shape

You can change the default shape of dots. By default it's a CircleBorder.

You can change the no active and active dot shape.

Custom dots shape

new DotsIndicator(
  dotsCount: pageLength,
  position: currentIndexPage,
  decorator: DotsDecorator(
    shape: const Border(),
    activeShape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
  ),
);

Custom shape for each dot

You can customize the shape of each dot, for inactive and/or active dots.

For that, use shapes and/or activeShapes params.

new DotsIndicator(
  dotsCount: pageLength,
  position: currentIndexPage,
  decorator: DotsDecorator(
    shapes: [
      RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
      RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
      RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0)),
    ],
    activeShapes: [
      RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
      RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
      RoundedRectangleBorder(borderRadius: BorderRadius.circular(25.0)),
    ],
  ),
);

Change the space between dots

By default a dot have a margin of 6 pixels on his left and right. It's EdgeInsets.symmetric(horizontal: 6.0). But if you want you can change it, for example to increase the space between dots or to add top margin.

Custom dots space

new DotsIndicator(
  dotsCount: pageLength,
  position: currentIndexPage,
  decorator: DotsDecorator(
    spacing: const EdgeInsets.all(10.0),
  ),
);

Axis and reverse property

There is two other property, axis and reversed. Axis is to display dots indicator horizontally (default) or vertically. Also, you can set reversed: true to reverse the order of dots. (default: false).

For example, if you want to display the dots indicator vertically, but with the first dots on bottom : Set axis: Axis.vertical and reversed: true. Obviously, you can use reversed with Axis.horizontal.

onTap property

You can add onTap property, to listen when a dot has been pressed. Exemple:

onTap: (position) {
  setState(() => _currentPos = position);
}

dots_indicator's People

Contributors

davystrong avatar ghenry avatar hlavki avatar ivansapr avatar macacoazul01 avatar maherjaafar avatar pyozer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dots_indicator's Issues

Delayed transition

I have a Pageview widget setup along with dots indicator. When the page changes the "position" of the dot also changes. So the dot transition happens immediately even before the page transition completes. A "delay" property would be great to keep both dot and the page transitions in sync.

DotsIndicator center

Hi,

I noticed that ColorLoader is not well centered. Reason is that only the right padding is added in the _ColorLoaderState build function, so dots are shifted left as a result.
It can be fixed if padding for dots is set in following order:

padding: const EdgeInsets.only(left: 4.0, right: 8.0)
padding: const EdgeInsets.only(right: 8.0)
padding: const EdgeInsets.only(right: 4.0)

I guess since it is a small fix I post it here..but if you want I can send a pull request too.

Cheers,
Milos

Support null safety

The library 'package:dots_indicator/dots_indicator.dart' is legacy, and should not be imported into a null safe library.
Try migrating the imported library.
Error: This project cannot run with sound null safety, because one or more project dependencies do not
support null safety:

- dots_indicator
dependencies:
  dots_indicator: ^1.2.0

PageView / PageController integration

Hi! Great library, thanks for writing it.

I wrote a wrapper to integrate these indicators with flutter's built-in PageController. I'm posting it here in case it's a useful addition. Feel free to assign me a PR if this should be integrated with DotsIndicator, or close this ticket if it's out of scope.

What this does:

  1. registers itself with PageController.addListener so it receives updates
  2. connects DotsIndicator.onTap to the PageController so taps update the PageView position
class ListenerDots extends StatefulWidget {
  final PageController pos;
  final int dotsCount;
  const ListenerDots({Key? key, required this.pos, required this.dotsCount})
      : super(key: key);

  @override
  State<StatefulWidget> createState() => _ListenerDotsState();
}

class _ListenerDotsState extends State<ListenerDots> {
  double lastPos = 0;

  @override
  void initState() {
    widget.pos.addListener(updatePage);
    super.initState();
  }

  /// listen handler
  updatePage() => setState(() {
        lastPos = widget.pos.page ?? 0.0;
      });

  @override
  void dispose() {
    widget.pos.removeListener(updatePage);
    super.dispose();
  }

  onTap(double offset) {
    widget.pos.animateToPage(
      offset.toInt(),
      duration: const Duration(milliseconds: 200),
      curve: Curves.easeInOut,
    );
  }

  @override
  Widget build(BuildContext context) => DotsIndicator(
      dotsCount: widget.dotsCount, position: lastPos, onTap: onTap);
}

Overflow with flutter web

The plugin is working perfectly for the mobile app (Android / iOS)

When I try to use this plugin with flutter web it works fine except when I try to resize the window.
When I resize the window, more points are added to the dots indicator and an overflow appear on the right.

Error:

The relevant error-causing widget was:
Row org-dartlang-app:///packages/dots_indicator/src/dots_indicator.dart:61:11
The overflowing RenderFlex has an orientation of Axis.horizontal.
The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and black striped pattern. This is usually caused by the contents being too big for the RenderFlex.

Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the RenderFlex to fit within the available space instead of being sized to their natural size.
This is considered an error condition because it indicates that there is content that cannot be seen. If the content is legitimately bigger than the available space, consider clipping it with a ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex, like a ListView.

Latest release is patch version bump but breaking change

Latest change (position to int) is a breaking change and as such can break other (library) packages which depend on dots_inidicator.

Would it be possible to pull the latest version and re-release it as a breaking change (3.0.0)?

Why is 'position' a double?

To me it makes sense that both 'dotCount' and 'position' should be int ('dotCount' is the number of dots, and 'position' is the index of the current dot). Why is 'position' a double? What does it mean for position to be 1.5?

Failed assertion: line 31 pos 16: 'dotsCount != null && dotsCount > 0': is not true

Hi,

I am getting error as:
'package:dots_indicator/src/dots_indicator.dart': Failed assertion: line 31 pos 16: 'dotsCount != null && dotsCount > 0': is not true.

In init state part I am getting a data from remote server. Once the data verify I set the loadIndicator true so I can show the page. in area that data verify before setting the page loadIndicator to true in setState I set the pageLength. pageLength is integer and it totals of list of the data that I get from database. Everything works. Even I set the dotsCount = pageLength;

Any idea why I am keep getting this error?

My code:

return Scaffold(
    body: new Form(
      key: _formKey,
      child: Stack(
        children: [
          Column(
            children: [
              // IMAGE AREA TOP
              Container(
                height: 230.0,
                width: MediaQuery.of(context).size.width - 50.0,
                child: PageView.builder(
                  scrollDirection: Axis.horizontal,
                  controller: _pageController,
                  onPageChanged: ((_page) {
                    setState(() {
                      int _currentValue = int.parse('$_page');
                      currentIndexPage = _currentValue;
                    });
                  }),
                  itemCount: pageLength,
                  itemBuilder: (context, index) => _creditCard(context, currentIndexPage),
                ),
              ),
              // DOTS INDICTOR AREA
              Padding(
                padding: const EdgeInsets.only(top: 16.0),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    DotsIndicator(
                      dotsCount: pageLength,
                      position: double.parse('$currentIndexPage'),
                      decorator: DotsDecorator(
                        color: Colors.black38,
                        activeColor: Colors.red,
                        size: const Size.square(9.0),
                        activeSize: const Size(18.0, 9.0),
                        activeShape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
                      ),
                    )
                  ],
                ),
              ),

flutter doctor -v:

[✓] Flutter (Channel stable, 1.22.6, on macOS 11.2.2 20D80 darwin-x64, locale en-GB)
    • Flutter version 1.22.6 at /Users/*********/flutter
    • Framework revision 9b2d32b605 (6 weeks ago), 2021-01-22 14:36:39 -0800
    • Engine revision 2f0af37152
    • Dart version 2.10.5

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/*********/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = /Users/*********/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.4, Build version 12D4e
    • CocoaPods version 1.10.1

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin installed
    • Dart plugin version 201.9335
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[✓] IntelliJ IDEA Community Edition (version 2020.3.2)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin installed
    • Dart plugin version 203.6912

[✓] Connected device (1 available)
    • iPhone 11 (mobile) • 92E3**************************************E72 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-4 (simulator)





Dots direction

Hey Thanks for the awesome package. This made my job very easy. However the direction property is missing. I would like to use a vertical indicator rather horizontal. Do you have plans to upgrade the plugin anytime soon?

Center the widget

It seems the widget is taking all page width and is left centered.

How to center this DotIndicator widget ?

Question: Change color of inactive dots?

Hi there ! Just wondering if there is functionality to change the color of the inactive dots. I did not see it explicitly and it's very possible I overlooked something!

When there are too many page numbers.

dots_indicator 2.0.0
When there are too many page numbers.

log:

The following assertion was thrown during layout:
A RenderFlex overflowed by 144 pixels on the right.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.