This repository has been archived by the owner on Mar 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 95
/
select_guided_storage_page.dart
134 lines (123 loc) · 4.56 KB
/
select_guided_storage_page.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import 'package:filesize/filesize.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:provider/provider.dart';
import 'package:ubuntu_wizard/constants.dart';
import 'package:ubuntu_wizard/widgets.dart';
import '../../l10n.dart';
import '../../services.dart';
import 'select_guided_storage_model.dart';
/// Select a storage for guided partitioning.
class SelectGuidedStoragePage extends StatefulWidget {
/// Use [SelectGuidedStoragePage.create] instead.
@visibleForTesting
const SelectGuidedStoragePage({Key? key}) : super(key: key);
/// Creates a [SelectGuidedStoragePage] with [SelectGuidedStorageModel].
static Widget create(BuildContext context) {
final service = getService<DiskStorageService>();
return ChangeNotifierProvider(
create: (context) => SelectGuidedStorageModel(service),
child: const SelectGuidedStoragePage(),
);
}
@override
_SelectGuidedStoragePageState createState() =>
_SelectGuidedStoragePageState();
}
class _SelectGuidedStoragePageState extends State<SelectGuidedStoragePage> {
@override
void initState() {
super.initState();
final model = Provider.of<SelectGuidedStorageModel>(context, listen: false);
model.loadGuidedStorage();
}
String prettyFormatPartition(Disk disk, Partition partition) {
return '${disk.sysname}${partition.number}';
}
/// Formats a disk in a pretty way e.g. "/dev/sda ATA Maxtor (123 GB)"
String prettyFormatStorage(Disk disk) {
final fullName = <String?>[
disk.model,
disk.vendor,
].where((p) => p?.isNotEmpty == true).join(' ');
final size = filesize(disk.size);
return '${disk.path} - $size $fullName';
}
@override
Widget build(BuildContext context) {
final model = Provider.of<SelectGuidedStorageModel>(context);
final lang = AppLocalizations.of(context);
final flavor = Flavor.of(context);
return WizardPage(
title: Text(lang.selectGuidedStoragePageTitle(flavor.name)),
content: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
Text(lang.selectGuidedStorageDropdownLabel),
const SizedBox(width: kContentSpacing),
Expanded(
child: DropdownBuilder<int>(
values: List.generate(model.storages.length, (i) => i),
selected: model.selectedIndex,
onSelected: (i) => model.selectStorage(i!),
itemBuilder: (context, index, child) {
final storage = model.storages[index];
return Text(
prettyFormatStorage(storage),
key: ValueKey(index),
);
},
),
)
],
),
const SizedBox(height: kContentSpacing),
if (model.selectedStorage != null)
Text(lang.selectGuidedStorageInfoLabel),
const SizedBox(height: kContentSpacing * 2),
if (model.selectedStorage != null)
Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SvgPicture.asset(
'assets/select_guided_storage/ubuntu.svg',
width: 48,
height: 48,
),
const SizedBox(height: kContentSpacing / 2),
Text(
flavor.name,
style: Theme.of(context).textTheme.headline6,
),
const SizedBox(height: kContentSpacing / 2),
Text(model.selectedStorage?.path ?? ''),
const SizedBox(height: kContentSpacing / 2),
Text(
filesize(model.selectedStorage?.size ?? 0),
style: Theme.of(context).textTheme.headline5,
),
],
),
),
],
),
actions: <WizardAction>[
WizardAction.back(context),
WizardAction(
label: lang.selectGuidedStorageInstallNow,
onActivated: () async {
await model.saveGuidedStorage();
await Wizard.of(context).next();
// If the user returns back to select another disk, the previously
// configured guided storage must be reset to avoid multiple disks
// being configured for guided partitioning.
await model.resetGuidedStorage();
},
)
],
);
}
}