From d323eec8ed3d7addccfb14f27af311173fce5c19 Mon Sep 17 00:00:00 2001 From: Peter Axelsson Date: Mon, 30 Sep 2024 20:12:58 +0000 Subject: [PATCH 1/2] added scroll controller in forms --- lib/src/pages/operating_system_selection.dart | 111 +++++++++--------- lib/src/pages/option_selection.dart | 42 ++++--- lib/src/pages/version_selection.dart | 69 +++++------ 3 files changed, 114 insertions(+), 108 deletions(-) diff --git a/lib/src/pages/operating_system_selection.dart b/lib/src/pages/operating_system_selection.dart index 640593b..4547efd 100644 --- a/lib/src/pages/operating_system_selection.dart +++ b/lib/src/pages/operating_system_selection.dart @@ -16,6 +16,7 @@ class OperatingSystemSelection extends StatefulWidget { class _OperatingSystemSelectionState extends State { var term = ""; final focusNode = FocusNode(); + final ScrollController _scrollController = ScrollController(); @override void initState() { @@ -23,6 +24,12 @@ class _OperatingSystemSelectionState extends State { super.initState(); } + @override + void dispose() { + _scrollController.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -63,64 +70,56 @@ class _OperatingSystemSelectionState extends State { ), ), ), - body: SingleChildScrollView( - child: Column( - children: [ - FutureBuilder( - future: gOperatingSystems, - builder: (BuildContext context, AsyncSnapshot snapshot) { - if (snapshot.hasData) { - List list = snapshot.data! - .where((os) => os.name.toLowerCase().contains(term.toLowerCase())) - .toList(); - return ListView.builder( - padding: const EdgeInsets.only(top: 4), - shrinkWrap: true, - itemCount: list.length, - itemBuilder: (context, index) { - var item = list[index]; - Widget icon; + body: Scrollbar( + controller: _scrollController, + child: FutureBuilder( + future: gOperatingSystems, + builder: (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.hasData) { + List list = snapshot.data! + .where((os) => + os.name.toLowerCase().contains(term.toLowerCase())) + .toList(); + return ListView.builder( + controller: _scrollController, + itemCount: list.length, + itemBuilder: (context, index) { + var item = list[index]; + Widget icon; - if (osIcons.containsKey(item.code)) { - icon = SvgPicture.asset( - osIcons[item.code]!, - width: 32, - height: 32, - ); - } else { - // Replace with generic icon - icon = const Icon(Icons.computer, size: 32); - } - return Card( - child: ListTile( - title: Text(item.name), - leading: icon, - onTap: () { - Navigator.of(context).pop(item); - }, - ), - ); - }, + if (osIcons.containsKey(item.code)) { + icon = SvgPicture.asset( + osIcons[item.code]!, + width: 32, + height: 32, + ); + } else { + icon = const Icon(Icons.computer, size: 32); + } + return Card( + child: ListTile( + title: Text(item.name), + leading: icon, + onTap: () { + Navigator.of(context).pop(item); + }, + ), ); - } else { - return Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Column( - children: [ - const Padding( - padding: EdgeInsets.all(16.0), - child: CircularProgressIndicator() - ), - Text(context.t('Loading available downloads')), - ], - ) - ], - ); - } - } - ), - ] + }, + ); + } else { + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const CircularProgressIndicator(), + const SizedBox(height: 16), + Text(context.t('Loading available downloads')), + ], + ), + ); + } + }, ), ), ); diff --git a/lib/src/pages/option_selection.dart b/lib/src/pages/option_selection.dart index 819bdc3..f2b80a9 100644 --- a/lib/src/pages/option_selection.dart +++ b/lib/src/pages/option_selection.dart @@ -15,6 +15,7 @@ class OptionSelection extends StatefulWidget { class _OptionSelectionState extends State { var term = ""; final focusNode = FocusNode(); + final ScrollController _scrollController = ScrollController(); @override void initState() { @@ -22,6 +23,12 @@ class _OptionSelectionState extends State { super.initState(); } + @override + void dispose() { + _scrollController.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { var list = widget.version.options @@ -68,25 +75,22 @@ class _OptionSelectionState extends State { ), ), ), - body: SingleChildScrollView( - child: Column( - children: [ - ListView.builder( - shrinkWrap: true, - itemCount: list.length, - itemBuilder: (context, index) { - var item = list[index]; - return Card( - child: ListTile( - title: Text(item.option), - onTap: () { - Navigator.of(context).pop(item); - }, - ), - ); - }, - ), - ], + body: Scrollbar( + controller: _scrollController, + child: ListView.builder( + controller: _scrollController, + itemCount: list.length, + itemBuilder: (context, index) { + var item = list[index]; + return Card( + child: ListTile( + title: Text(item.option), + onTap: () { + Navigator.of(context).pop(item); + }, + ), + ); + }, ), ), ); diff --git a/lib/src/pages/version_selection.dart b/lib/src/pages/version_selection.dart index 226cc31..2531795 100644 --- a/lib/src/pages/version_selection.dart +++ b/lib/src/pages/version_selection.dart @@ -19,6 +19,7 @@ class VersionSelection extends StatefulWidget { class _VersionSelectionState extends State { var term = ""; final focusNode = FocusNode(); + final ScrollController _scrollController = ScrollController(); @override void initState() { @@ -26,6 +27,12 @@ class _VersionSelectionState extends State { super.initState(); } + @override + void dispose() { + _scrollController.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { var list = widget.operatingSystem.versions @@ -73,41 +80,37 @@ class _VersionSelectionState extends State { ), ), ), - body: SingleChildScrollView( - child: Column( - children: [ - ListView.builder( - padding: const EdgeInsets.only(top: 4), - shrinkWrap: true, - itemCount: list.length, - itemBuilder: (context, index) { - var item = list[index]; - return Card( - child: ListTile( - title: Text(item.version), - onTap: () { - if (item.options.length > 1) { + body: Scrollbar( + controller: _scrollController, + child: ListView.builder( + controller: _scrollController, + padding: const EdgeInsets.only(top: 4), + itemCount: list.length, + itemBuilder: (context, index) { + var item = list[index]; + return Card( + child: ListTile( + title: Text(item.version), + onTap: () { + if (item.options.length > 1) { + Navigator.of(context) + .push