Skip to content

Instantly share code, notes, and snippets.

@ciriousjoker
Created December 14, 2021 08:10
Show Gist options
  • Save ciriousjoker/0a54836f3805e9998adbf46da2134b8f to your computer and use it in GitHub Desktop.
Save ciriousjoker/0a54836f3805e9998adbf46da2134b8f to your computer and use it in GitHub Desktop.
PageView Scroll Physics test
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: darkBlue,
),
debugShowCheckedModeBanner: false,
home: const Scaffold(
body: Center(
child: ScrollTest(),
),
),
);
}
}
class ScrollTest extends StatefulWidget {
const ScrollTest({Key? key}) : super(key: key);
@override
_ScrollTestState createState() => _ScrollTestState();
}
class _ScrollTestState extends State<ScrollTest> {
late PageController _controller;
int _sliderNumber = 5000;
@override
void initState() {
super.initState();
_controller = PageController(
initialPage: 5000,
viewportFraction: 0.15,
);
}
@override
Widget build(BuildContext context) {
return SizedBox(
height: 75,
child: PageView.builder(
controller: _controller,
itemCount: 10000,
onPageChanged: (i) {
debugPrint('page changed to $i');
setState(() {
_sliderNumber = i;
});
},
scrollBehavior: const CupertinoScrollBehavior(),
itemBuilder: (context, i) => Container(
color: Colors.blue,
child: Center(
child: AnimatedScale(
scale: _sliderNumber == i ? 3 : 1,
duration: const Duration(milliseconds: 200),
curve: Curves.easeInOut,
child: Text(
i.toString(),
style: const TextStyle(fontSize: 20),
),
),
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment