搜索插件、代码仓与 APP 分类

插件详情v0.0.3

flutter_web_scrollbar

适用于 Flutter Web 的可自定义滚动条。

近 30 天下载
52
喜欢数
46
Pub 分数
30

安装插件

flutter pub add flutter_web_scrollbar

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

专为Flutter Web应用设计的可自定义滚动条。它通过提供一个视觉上吸引人且功能完善的滚动指示器,增强了用户体验,该指示器可适应Web特有的交互方式。滚动条支持自定义样式、位置和行为调整,便于集成到基于Web的Flutter项目中。它与ListView和SingleChildScrollView等标准可滚动控件无缝配合,确保在桌面和平板浏览器上的流畅滚动。

适合场景

  • 自定义网页应用中的滚动条
  • 改进长内容列表的用户体验
  • 增强网页界面的视觉设计
  • 与响应式布局集成
  • 支持桌面和平板滚动
  • 在不同网络平台创建一致的滚动指示器

主要特点

  • Web优化的滚动条设计
  • 完全可自定义的外观
  • 支持垂直和水平滚动
  • 与 ScrollViews 的轻松集成
  • 可配置的轨道和滑块样式
  • 在不同屏幕尺寸上的响应式行为

适合对象

  • Flutter 开发者构建 Web 应用程序
  • 寻求精致滚动 UI 的设计师
  • 需要一致的网页滚动条行为的项目
  • 包含大量可滚动内容的应用
  • 专注于网页特定用户体验改进的团队

使用建议

  • 不适用于移动平台
  • 每个可滚动控件都需要显式设置
  • 仅限网页平台
  • 可能需要额外的样式以兼容深色模式
  • 对非常大的可滚动列表的性能影响

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

flutter_web_scrollbar

A flutter web plugin for adding a customizable scrollbar to your web project. Scroll Bar Web

Usage

To use this plugin add flutter_web_scrollbar as a dependency in your pubspec.yaml file.

Adding the scrollbar to your webpage requires a few mandatory steps:

  1. The content of your page must be the child of a Scrollable Widget (i.e: SingleChildScrollView
  2. The scrollable widget and the FlutterWebScrollbar must be children in a parent Stack
  3. The scrollable widget must be listed first in the Stack
  4. The scrollable widget must have a ScrollController attached to it
  5. The FlutterWebScrollbar must receive a callBack function that accepts a DragUpdateDetails as a parameter.

Example

import 'package:flutter/material.dart';  
import 'package:flutter_web_scrollbar/flutter_web_scrollbar.dart';  
  
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,  
          ),  
        ],  
      ),  
    );  
  }  
}

Things to note about the above code:

  • Inside of our scrollCallBack function, we're updating the ScrollController that is attached to our scrollable widget. It's important to note that in the example, we are using a value of 3.5 to represent the theoretical height of our page content. The theoretical height of your page content may be different. For example, if you have to full height container as your content, you may want to use 2 rather than 3.5. Getting this value as correct as possible plays a big role in how accurate your scrolling will be.
  • Visit the repository here to submit issue reports and request changes
  • If you'd like to help with the upkeep for the plugin, email me at caira102797@gmail.com

Buy Me A Pizza

所属分类

源码仓库

使用此插件的项目

暂无相关数据。