feat: added a textfield to search the version of an operating system
This commit is contained in:
parent
60b96496f2
commit
9e55104f71
|
@ -1,6 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
|
||||||
import 'package:gettext_i18n/gettext_i18n.dart';
|
import 'package:gettext_i18n/gettext_i18n.dart';
|
||||||
|
import 'package:tuple/tuple.dart';
|
||||||
|
|
||||||
import '../model/operating_system.dart';
|
import '../model/operating_system.dart';
|
||||||
import '../model/option.dart';
|
import '../model/option.dart';
|
||||||
|
@ -18,12 +18,61 @@ class VersionSelection extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _VersionSelectionState extends State<VersionSelection> {
|
class _VersionSelectionState extends State<VersionSelection> {
|
||||||
|
var term = "";
|
||||||
|
final focusNode = FocusNode();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
focusNode.requestFocus();
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
var list = widget.operatingSystem.versions
|
||||||
|
.where((version) =>
|
||||||
|
version.version.toLowerCase().contains(term.toLowerCase()))
|
||||||
|
.toList();
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(context
|
title: Text(context
|
||||||
.t('Select version for {0}', args: [widget.operatingSystem.name])),
|
.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(
|
body: SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
|
@ -31,21 +80,19 @@ class _VersionSelectionState extends State<VersionSelection> {
|
||||||
ListView.builder(
|
ListView.builder(
|
||||||
padding: const EdgeInsets.only(top: 4),
|
padding: const EdgeInsets.only(top: 4),
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
itemCount: widget.operatingSystem.versions.length,
|
itemCount: list.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
var item = widget.operatingSystem.versions[index];
|
var item = list[index];
|
||||||
return Card(
|
return Card(
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
title: Text(item.version),
|
title: Text(item.version),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (widget
|
if (item.options.length > 1) {
|
||||||
.operatingSystem.versions[index].options.length >
|
|
||||||
1) {
|
|
||||||
Navigator.of(context)
|
Navigator.of(context)
|
||||||
.push<Option>(MaterialPageRoute(
|
.push<Option>(MaterialPageRoute(
|
||||||
fullscreenDialog: true,
|
fullscreenDialog: true,
|
||||||
builder: (context) => OptionSelection(
|
builder: (context) =>
|
||||||
widget.operatingSystem.versions[index])))
|
OptionSelection(list[index])))
|
||||||
.then((selection) {
|
.then((selection) {
|
||||||
if (selection != null) {
|
if (selection != null) {
|
||||||
Navigator.of(context)
|
Navigator.of(context)
|
||||||
|
@ -53,8 +100,8 @@ class _VersionSelectionState extends State<VersionSelection> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Navigator.of(context).pop(Tuple2<Version, Option?>(item,
|
Navigator.of(context).pop(Tuple2<Version, Option?>(
|
||||||
widget.operatingSystem.versions[index].options[0]));
|
item, list[index].options[0]));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue