overlapped_slider 1.0.0
overlapped_slider: ^1.0.0 copied to clipboard
A horizontal overlapped slider widget. The center widget will be at the top of the stack.
example/lib/main.dart
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:overlapped_slider/overlapped_slider.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Overlapped Slider',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Overlapped Slider'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, this.title}) : super(key: key);
final String? title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
//Generate a list of widgets. You can use another way
List<Widget> widgets1 = List.generate(
5,
(index) => ClipRRect(
borderRadius: const BorderRadius.all(
Radius.circular(5.0),
),
child: Image.asset(
'assets/images/$index.jpg', //Images stored in assets folder
fit: BoxFit.fill,
),
),
);
List<Widget> widgets2 = List.generate(
5,
(index) => Container(
height: 60,
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
image: DecorationImage(
fit: BoxFit.contain,
image: AssetImage("assets/images/$index.jpg"))),
),
);
@override
Widget build(BuildContext context) {
var screenWidth = MediaQuery.of(context).size.width;
var screenHeight = MediaQuery.of(context).size.height;
return Scaffold(
backgroundColor: Colors.blueGrey,
//Wrap with Center to place the Slider center of the screen
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(
height: 20,
),
SizedBox(
//Wrap the OverlappedSliderwidget with SizedBox to fix a height. No need to specify width.
height: min(screenWidth / 3.3 * (16 / 9), screenHeight * .9),
child: OverlappedSlider(
widgets: widgets1, //List of widgets
currentIndex: 2,
onClicked: (index) {},
),
),
const SizedBox(
height: 20,
),
SizedBox(
//Wrap the OverlappedSlider widget with SizedBox to fix a height. No need to specify width.
height: min(
screenWidth / 3 * (2 / 1), screenHeight * 0.5 * screenWidth),
child: OverlappedSlider(
widgets: widgets2, //List of widgets
currentIndex: 2,
onClicked: (index) {},
),
),
],
),
);
}
}