sing_swiper 0.0.1 sing_swiper: ^0.0.1 copied to clipboard
sing_swiper
import 'package:flutter/material.dart';
import 'package:sing_page_indicator/enum/page_indicator_layout.dart';
import 'package:sing_swiper/sing_swiper.dart';
import 'src/ExampleCustom.dart';
import 'src/config.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(primarySwatch: Colors.blue),
home: const MyHomePage(title: 'Flutter Swiper'),
routes: {
'/example07': (BuildContext context) => ScaffoldWidget(title: "Custom All",child: const ExampleCustom(),)
},
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(widget.title)),
body: ListView(
children: [
SizedBox(
height: 100,
width: 100,
child: Swiper(
autoplay: true,
itemCount: 10,
itemBuilder: (c, i) {
return Container(
alignment: Alignment.center,
color: Colors.red,
child: Text("$i"));
},
),
),
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: 180,
height: 100,
child: Swiper(
itemBuilder: (BuildContext context, int index) => Image.asset(images[index], fit: BoxFit.fill),
indicatorLayout: PageIndicatorLayout.COLOR,
autoplay: true,
itemCount: images.length,
pagination: const SwiperPagination(),
control: const SwiperControl(),
),
),
SizedBox(
width: 180,
height: 100,
child: Swiper(
itemBuilder: (BuildContext context, int index) => Image.asset(images[index], fit: BoxFit.fill),
autoplay: true,
itemCount: images.length,
scrollDirection: Axis.vertical,
pagination: const SwiperPagination(alignment: Alignment.centerRight),
control: const SwiperControl(),
),
),
],
),
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: 180,
height: 130,
child: Swiper(
itemBuilder: (BuildContext context, int index) => Image.asset(images[index], fit: BoxFit.fill),
autoplay: true,
itemCount: images.length,
pagination: const SwiperPagination(builder: SwiperPagination.fraction),
control: const SwiperControl(),
),
),
SizedBox(
width: 180,
height: 130,
child: Swiper(
itemBuilder: (BuildContext context, int index) => Image.asset(images[index], fit: BoxFit.fill),
autoplay: true,
itemCount: images.length,
scrollDirection: Axis.vertical,
pagination: const SwiperPagination(alignment: Alignment.centerRight, builder: SwiperPagination.fraction),
),
),
],
),
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: 180,
height: 130,
child: Swiper(
itemBuilder: (BuildContext context, int index) => Image.asset(images[index], fit: BoxFit.fill),
autoplay: true,
itemCount: images.length,
pagination: SwiperPagination(
margin: EdgeInsets.all(0.0),
builder: SwiperCustomPagination(builder: (BuildContext context, SwiperPluginConfig config) {
return ConstrainedBox(
child: Container(
child: Text('自定义文字 ${config.activeIndex + 1}/${config.itemCount}')),
constraints: BoxConstraints.expand(height: 30.0),
);
})),
control: SwiperControl(),
),
),
SizedBox(
width: 180,
height: 130,
child: Swiper(
itemBuilder: (BuildContext context, int index) => Image.asset(images[index], fit: BoxFit.fill),
autoplay: true,
itemCount: images.length,
pagination: SwiperPagination(
margin: EdgeInsets.all(0.0),
builder: SwiperCustomPagination(builder: (BuildContext context, SwiperPluginConfig config) {
return ConstrainedBox(
child: Row(
children: <Widget>[
Text('自定义文字 ${config.activeIndex + 1}/${config.itemCount}'),
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: DotSwiperPaginationBuilder(
color: Colors.grey,
activeColor: Colors.black,
size: 10,
activeSize: 12)
.build(context, config),
),
)
],
),
constraints: BoxConstraints.expand(height: 30.0),
);
})),
control: SwiperControl(color: Colors.redAccent),
),
),
],
),
const SizedBox(height: 10),
SizedBox(
height: 150,
child: Stack(
children: <Widget>[
ConstrainedBox(
constraints: const BoxConstraints.expand(),
child: Image.asset("images/bg.jpeg", fit: BoxFit.fill),
),
Swiper.children(
autoplay: true,
pagination: const SwiperPagination(
margin: EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 30.0),
builder: DotSwiperPaginationBuilder(
color: Colors.grey,
activeColor: Colors.white,
size: 20.0,
activeSize: 20.0)),
children: <Widget>[
Image.asset("images/1.png", fit: BoxFit.contain),
Image.asset("images/2.png", fit: BoxFit.contain),
Image.asset("images/3.png", fit: BoxFit.contain)
],
)
],
),
),
ListTile(
onTap: () => Navigator.of(context).pushNamed('/example07'),
title: const Text('Custom'),
subtitle: const Text('Custom all properties'),
),
],
),
);
}
}
class ScaffoldWidget extends StatelessWidget {
final Widget child;
final String title;
ScaffoldWidget({required this.child, required this.title});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: child,
);
}
}