如何在颤动中拥有这样的滚动条视图?

问题描述 投票:-2回答:1

enter image description here

我希望在列中有这样的滚动条视图。

那我怎么能用颤动呢?

我试过了

SingleChildScrollView(
            ....
          ),

但是没有滚动条出现,我不知道要制作它们

dart flutter scrollbar
1个回答
0
投票

你可以使用this project

pubspec.yaml

dev_dependencies:
  flutter_test:
    sdk: flutter
  draggable_scrollbar: 0.0.4

代码:

import 'package:flutter/material.dart';
import 'package:draggable_scrollbar/draggable_scrollbar.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  ScrollController _rrectController = ScrollController();
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Test",
      home: Scaffold(
        body: Center(
          child: DraggableScrollbar.rrect(
            controller: _rrectController,
            backgroundColor: Colors.blue,
            child: ListView.builder(
              controller: _rrectController,
              itemCount: 100,
              itemExtent: 100.0,
              itemBuilder: (context, index) {
                return Container(
                  padding: EdgeInsets.all(8.0),
                  child: Material(
                    elevation: 4.0,
                    borderRadius: BorderRadius.circular(4.0),
                    color: Colors.green[index % 9 * 100],
                    child: Center(
                      child: Text(index.toString()),
                    ),
                  ),
                );
              },
            ),
          ),
        ),
      ),
    );
  }
}

结果:enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.