You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `flutter_carousel_widget` package comes with a few [predefined slide indicators](https://github.com/nixrajput/flutter_carousel_widget/tree/master/lib/src/indicators) with their own unique behaviors. This helps drastically and brings focus towards the actual implementation of your carousel widget.
248
+
249
+
However, there might be cases where you want to control the look or behavior of the slide indicator or implement a totally new one. You can do that by implementing the `SlideIndicator` contract.
250
+
251
+
The following example implements an indicator which tells the percentage of the slide the user is on:
252
+
```dart
253
+
class SlidePercentageIndicator implements SlideIndicator {
254
+
SlidePercentageIndicator({
255
+
this.decimalPlaces = 0,
256
+
this.style,
257
+
});
258
+
259
+
/// The number of decimal places to show in the output
260
+
final int decimalPlaces;
261
+
262
+
/// The text style to be used by the percentage text
263
+
final TextStyle? style;
264
+
265
+
@override
266
+
Widget build(int currentPage, double pageDelta, int itemCount) {
267
+
if (itemCount < 2) return const SizedBox.shrink();
268
+
final step = 100 / (itemCount - 1);
269
+
final percentage = step * (pageDelta + currentPage);
270
+
return Center(
271
+
child: Text(
272
+
'${percentage.toStringAsFixed(decimalPlaces)}%',
273
+
style: style ??
274
+
const TextStyle(
275
+
fontSize: 24,
276
+
fontWeight: FontWeight.w600,
277
+
),
278
+
),
279
+
);
280
+
}
281
+
}
282
+
```
283
+
244
284
## Contributing
245
285
246
286
If you would like to contribute to this project, feel free to fork the repository, make your changes, and submit a pull request. Please follow the guidelines in the [CONTRIBUTING.md](CONTRIBUTING.md) file.
0 commit comments