feat: added a textfield to search the version of an operating system

This commit is contained in:
Yannick Mauray 2022-11-11 15:49:25 +01:00
parent 60b96496f2
commit 9e55104f71
No known key found for this signature in database
GPG Key ID: 67C4AAC5E99CB909
1 changed files with 57 additions and 10 deletions

View File

@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:tuple/tuple.dart';
import 'package:gettext_i18n/gettext_i18n.dart';
import 'package:tuple/tuple.dart';
import '../model/operating_system.dart';
import '../model/option.dart';
@ -18,12 +18,61 @@ class VersionSelection extends StatefulWidget {
}
class _VersionSelectionState extends State<VersionSelection> {
var term = "";
final focusNode = FocusNode();
@override
void initState() {
focusNode.requestFocus();
super.initState();
}
@override
Widget build(BuildContext context) {
var list = widget.operatingSystem.versions
.where((version) =>
version.version.toLowerCase().contains(term.toLowerCase()))
.toList();
return Scaffold(
appBar: AppBar(
title: Text(context
.t('Select version for {0}', args: [widget.operatingSystem.name])),
bottom: PreferredSize(
preferredSize: const Size.fromHeight(kToolbarHeight),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration: BoxDecoration(
color: Theme.of(context).canvasColor,
),
child: Padding(
padding: const EdgeInsets.all(8),
child: Material(
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const Icon(Icons.search),
Expanded(
child: TextField(
focusNode: focusNode,
decoration: InputDecoration.collapsed(
hintText: context.t('Search version'),
),
onChanged: (value) {
setState(() {
term = value;
});
},
),
),
],
),
),
),
),
),
),
),
body: SingleChildScrollView(
child: Column(
@ -31,21 +80,19 @@ class _VersionSelectionState extends State<VersionSelection> {
ListView.builder(
padding: const EdgeInsets.only(top: 4),
shrinkWrap: true,
itemCount: widget.operatingSystem.versions.length,
itemCount: list.length,
itemBuilder: (context, index) {
var item = widget.operatingSystem.versions[index];
var item = list[index];
return Card(
child: ListTile(
title: Text(item.version),
onTap: () {
if (widget
.operatingSystem.versions[index].options.length >
1) {
if (item.options.length > 1) {
Navigator.of(context)
.push<Option>(MaterialPageRoute(
fullscreenDialog: true,
builder: (context) => OptionSelection(
widget.operatingSystem.versions[index])))
builder: (context) =>
OptionSelection(list[index])))
.then((selection) {
if (selection != null) {
Navigator.of(context)
@ -53,8 +100,8 @@ class _VersionSelectionState extends State<VersionSelection> {
}
});
} else {
Navigator.of(context).pop(Tuple2<Version, Option?>(item,
widget.operatingSystem.versions[index].options[0]));
Navigator.of(context).pop(Tuple2<Version, Option?>(
item, list[index].options[0]));
}
},
),