Skip to main content

Command Palette

Search for a command to run...

Scrollable Widget and Attributes

Updated
2 min read
Scrollable Widget and Attributes
V

"Hello World, I'm Vinit Mepani, a coding virtuoso driven by passion, fueled by curiosity, and always poised to conquer challenges. Picture me as a digital explorer, navigating through the vast realms of code, forever in pursuit of innovation.

In the enchanting kingdom of algorithms and syntax, I wield my keyboard as a magical wand, casting spells of logic and crafting solutions to digital enigmas. With each line of code, I embark on an odyssey of learning, embracing the ever-evolving landscape of technology.

Eager to decode the secrets of the programming universe, I see challenges not as obstacles but as thrilling quests, opportunities to push boundaries and uncover new dimensions in the realm of possibilities.

In this symphony of zeros and ones, I am Vinit Mepani, a coder by passion, an adventurer in the digital wilderness, and a seeker of knowledge in the enchanting world of code. Join me on this quest, and let's create digital wonders together!"

Scrollable content is a fundamental aspect of many Flutter applications. Flutter provides the Scrollbar widget to enhance the user experience by adding a scrollbar to scrollable widgets. In this blog post, we'll explore the Scrollbar widget, its key attributes, and provide a comprehensive example to illustrate its usage.

The Scrollbar widget in Flutter is used to add a scrollbar to a scrollable widget, making it easier for users to navigate through the content, especially when dealing with lengthy or large datasets.

Attributes of Scrollbar:

  1. child (required):

    • The scrollable widget to which the scrollbar will be applied.
  2. isAlwaysShown:

    • A boolean value indicating whether the scrollbar should always be visible or only appear during scrolling.
  3. thickness:

    • The thickness of the scrollbar.
  4. hoverThickness:

    • The thickness of the scrollbar when it is being hovered over.
  5. radius:

    • The radius of the scrollbar thumb's rounded corners.
  6. showTrackOnHover:

    • A boolean value indicating whether the scrollbar track should be visible when hovered over.

Example: Let's create a simple Flutter app that includes a Scrollbar for a ListView widget to demonstrate how the Scrollbar works.

// main.dart

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Scrollbar Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Scrollbar Example'),
      ),
      body: Scrollbar(
        // Attributes for Scrollbar customization
        thumbVisibility: true,
        thickness: 10.0,
        radius: Radius.circular(8.0),
        trackVisibility: true,
        child: ListView.builder(
          itemCount: 100,
          itemBuilder: (context, index) => Column(
            children: [
              ListTile(
                title: Text(
                  '   Item $index',
                style: TextStyle(color:Color.fromARGB(255, 230, 181, 5),))
                ,
                tileColor: index % 2 == 0 ? Colors.white : Colors.grey[200],
                // Add a divider between items
                contentPadding: EdgeInsets.symmetric(vertical: 8.0),
              ),
              // Add a divider after each item, except the last one
              if (index < 99) Divider(height: 0.5, color: Colors.grey),
            ],
          ),
        ),
      ),
    );
  }
}

Learn Flutter

Part 1 of 50

Explore Flutter's magic in crafting cross-platform apps effortlessly. Join the adventure!

More from this blog

Vinit Mepani (Flutter Developer)

270 posts

"Vinit Mepani, passionate coder! Dive into my Dart and Flutter journey on the blog. Let's master these tech wonders together. Happy coding! 🚀"