flutter_web_scrollbar 0.0.3 flutter_web_scrollbar: ^0.0.3 copied to clipboard
A customizable scrollbar for flutter web.
/*
*
* A sample app for the Flutter Web Basic Scrollbar
*
* */
import 'package:flutter/material.dart';
import 'package:flutter_web_scrollbar/flutter_web_scrollbar.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Web Basic Scroll',
home: LandingPage(),
);
}
}
class LandingPage extends StatefulWidget {
LandingPage({Key key}) : super(key: key);
@override
State<StatefulWidget> createState() {
return _LandingPageState();
}
}
class _LandingPageState extends State<LandingPage> {
ScrollController _controller;
@override
void initState() {
//Initialize the scrollController
_controller = ScrollController();
super.initState();
}
void scrollCallBack(DragUpdateDetails dragUpdate) {
setState(() {
// Note: 3.5 represents the theoretical height of all my scrollable content. This number will vary for you.
_controller.position.moveTo(dragUpdate.globalPosition.dy * 3.5);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Stack(
children: [
Container(
child: SingleChildScrollView(
//Assign the controller to my scrollable widget
controller: _controller,
child: Column(
children: [
Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
color: Colors.black,
),
Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
color: Colors.red,
),
Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
color: Colors.green,
),
Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
color: Colors.blue,
),
],
),
),
),
FlutterWebScroller(
//Pass a reference to the ScrollCallBack function into the scrollbar
scrollCallBack,
//Add optional values
scrollBarBackgroundColor: Colors.white,
scrollBarWidth: 20.0,
dragHandleColor: Colors.red,
dragHandleBorderRadius: 2.0,
dragHandleHeight: 40.0,
dragHandleWidth: 15.0,
),
],
),
);
}
}