feat: call Installer through Home View

This commit is contained in:
Alberto Ponces
2022-08-17 18:44:27 +01:00
parent 750f035104
commit 40f27b3a09
10 changed files with 139 additions and 78 deletions

View File

@ -22,6 +22,7 @@ class _PatchesSelectorViewState extends State<PatchesSelectorView> {
Widget build(BuildContext context) {
return ViewModelBuilder<PatchesSelectorViewModel>.reactive(
disposeViewModel: false,
fireOnModelReadyOnce: true,
onModelReady: (model) => model.initialize(),
viewModelBuilder: () => locator<PatchesSelectorViewModel>(),
builder: (context, model, child) => Scaffold(
@ -29,7 +30,7 @@ class _PatchesSelectorViewState extends State<PatchesSelectorView> {
child: Padding(
padding:
const EdgeInsets.symmetric(vertical: 4.0, horizontal: 12.0),
child: model.patches != null && model.patches!.isNotEmpty
child: model.patches.isNotEmpty
? Column(
children: [
SearchBar(
@ -84,16 +85,16 @@ class _PatchesSelectorViewState extends State<PatchesSelectorView> {
patches.clear();
return Expanded(
child: ListView.builder(
itemCount: model.patches!.length,
itemCount: model.patches.length,
itemBuilder: (context, index) {
model.patches!.sort((a, b) => a.simpleName.compareTo(b.simpleName));
model.patches.sort((a, b) => a.simpleName.compareTo(b.simpleName));
PatchItem item = PatchItem(
name: model.patches![index].name,
simpleName: model.patches![index].simpleName,
version: model.patches![index].version,
description: model.patches![index].description,
name: model.patches[index].name,
simpleName: model.patches[index].simpleName,
version: model.patches[index].version,
description: model.patches[index].description,
isSelected: model.selectedPatches.any(
(element) => element.name == model.patches![index].name,
(element) => element.name == model.patches[index].name,
),
);
patches.add(item);
@ -107,19 +108,19 @@ class _PatchesSelectorViewState extends State<PatchesSelectorView> {
patches.clear();
return Expanded(
child: ListView.builder(
itemCount: model.patches!.length,
itemCount: model.patches.length,
itemBuilder: (context, index) {
model.patches!.sort((a, b) => a.simpleName.compareTo(b.simpleName));
if (model.patches![index].simpleName.toLowerCase().contains(
model.patches.sort((a, b) => a.simpleName.compareTo(b.simpleName));
if (model.patches[index].simpleName.toLowerCase().contains(
query.toLowerCase(),
)) {
PatchItem item = PatchItem(
name: model.patches![index].name,
simpleName: model.patches![index].simpleName,
version: model.patches![index].version,
description: model.patches![index].description,
name: model.patches[index].name,
simpleName: model.patches[index].simpleName,
version: model.patches[index].version,
description: model.patches[index].description,
isSelected: model.selectedPatches.any(
(element) => element.name == model.patches![index].name,
(element) => element.name == model.patches[index].name,
),
);
patches.add(item);

View File

@ -9,7 +9,7 @@ import 'package:stacked/stacked.dart';
class PatchesSelectorViewModel extends BaseViewModel {
final PatcherAPI patcherAPI = locator<PatcherAPI>();
List<Patch>? patches = [];
List<Patch> patches = [];
List<Patch> selectedPatches = [];
Future<void> initialize() async {
@ -24,14 +24,12 @@ class PatchesSelectorViewModel extends BaseViewModel {
void selectPatches(List<PatchItem> patchItems) {
selectedPatches.clear();
if (patches != null) {
for (PatchItem item in patchItems) {
if (item.isSelected) {
Patch patch =
patches!.firstWhere((element) => element.name == item.name);
if (!selectedPatches.contains(patch)) {
selectedPatches.add(patch);
}
for (PatchItem item in patchItems) {
if (item.isSelected) {
Patch patch =
patches.firstWhere((element) => element.name == item.name);
if (!selectedPatches.contains(patch)) {
selectedPatches.add(patch);
}
}
}