Skip to content

Instantly share code, notes, and snippets.

@csells
Created September 5, 2021 19:14
Show Gist options
  • Select an option

  • Save csells/cccc4308fb8d16eb816fb0f0599a0a4f to your computer and use it in GitHub Desktop.

Select an option

Save csells/cccc4308fb8d16eb816fb0f0599a0a4f to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() => runApp(const App());
class App extends StatelessWidget {
static const title = 'Flutter App';
const App({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) => const MaterialApp(
title: title,
home: HomePage(),
);
}
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int _count = 0;
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: const Text(App.title)),
body: Scrollbar(
isAlwaysShown: true,
child: ListView(
shrinkWrap: true,
children: [
for (var i = 0; i != _count; ++i) ListTile(title: Text('item $i'))
],
),
),
floatingActionButton: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: FloatingActionButton(
onPressed: () => setState(() => _count--),
child: const Text('-'),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: FloatingActionButton(
onPressed: () => setState(() => _count++),
child: const Text('+'),
),
),
],
),
);
}
@Piinks
Copy link
Copy Markdown

Piinks commented Sep 5, 2021

Hi Chris, your manual scrollbar has isAlwaysShown: true, the automatically applied one on desktop does not have this set by default, which is why you cannot see it without scrolling.

You can set this using the theme, and I believe the automatically applied scrollbar will show up as you expect:

class App extends StatelessWidget {
  static const title = 'Flutter App';

  const App({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) =>  MaterialApp(
        title: title,
        home: HomePage(),
        theme: ThemeData(scrollbarTheme: ScrollbarThemeData(isAlwaysShown: true))
      );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment