Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added scroll controller in forms to make OS/Version/options lists scrollable #224

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 55 additions & 56 deletions lib/src/pages/operating_system_selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@ class OperatingSystemSelection extends StatefulWidget {
class _OperatingSystemSelectionState extends State<OperatingSystemSelection> {
var term = "";
final focusNode = FocusNode();
final ScrollController _scrollController = ScrollController();

@override
void initState() {
focusNode.requestFocus();
super.initState();
}

@override
void dispose() {
_scrollController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -63,64 +70,56 @@ class _OperatingSystemSelectionState extends State<OperatingSystemSelection> {
),
),
),
body: SingleChildScrollView(
child: Column(
children: [
FutureBuilder(
future: gOperatingSystems,
builder: (BuildContext context, AsyncSnapshot<List> 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<List> 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')),
],
),
);
}
},
),
),
);
Expand Down
42 changes: 23 additions & 19 deletions lib/src/pages/option_selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ class OptionSelection extends StatefulWidget {
class _OptionSelectionState extends State<OptionSelection> {
var term = "";
final focusNode = FocusNode();
final ScrollController _scrollController = ScrollController();

@override
void initState() {
focusNode.requestFocus();
super.initState();
}

@override
void dispose() {
_scrollController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
var list = widget.version.options
Expand Down Expand Up @@ -68,25 +75,22 @@ class _OptionSelectionState extends State<OptionSelection> {
),
),
),
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);
},
),
);
},
),
),
);
Expand Down
69 changes: 36 additions & 33 deletions lib/src/pages/version_selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@ class VersionSelection extends StatefulWidget {
class _VersionSelectionState extends State<VersionSelection> {
var term = "";
final focusNode = FocusNode();
final ScrollController _scrollController = ScrollController();

@override
void initState() {
focusNode.requestFocus();
super.initState();
}

@override
void dispose() {
_scrollController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
var list = widget.operatingSystem.versions
Expand Down Expand Up @@ -73,41 +80,37 @@ class _VersionSelectionState extends State<VersionSelection> {
),
),
),
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<Option>(MaterialPageRoute(
fullscreenDialog: true,
builder: (context) => OptionSelection(list[index])))
.then((selection) {
if (selection != null) {
Navigator.of(context)
.push<Option>(MaterialPageRoute(
fullscreenDialog: true,
builder: (context) =>
OptionSelection(list[index])))
.then((selection) {
if (selection != null) {
Navigator.of(context)
.pop(Tuple2<Version, Option?>(item, selection));
}
});
} else {
Navigator.of(context).pop(Tuple2<Version, Option?>(
item, list[index].options[0]));
.pop(Tuple2<Version, Option?>(item, selection));
}
},
),
);
},
),
],
});
} else {
Navigator.of(context).pop(
Tuple2<Version, Option?>(item, list[index].options[0]));
}
},
),
);
},
),
),
);
Expand Down