fluffychat/lib/pages/device_settings/device_settings_view.dart

101 lines
4.0 KiB
Dart
Raw Permalink Normal View History

2021-04-15 09:46:43 +02:00
import 'package:flutter/material.dart';
2021-10-26 18:50:34 +02:00
2021-04-15 09:46:43 +02:00
import 'package:flutter_gen/gen_l10n/l10n.dart';
2021-11-09 21:32:16 +01:00
import 'package:fluffychat/pages/device_settings/device_settings.dart';
2021-10-26 18:50:34 +02:00
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
2021-11-09 21:32:16 +01:00
import 'user_device_list_item.dart';
2021-04-15 09:46:43 +02:00
2021-05-22 09:13:47 +02:00
class DevicesSettingsView extends StatelessWidget {
2021-04-15 09:46:43 +02:00
final DevicesSettingsController controller;
2022-01-29 12:35:03 +01:00
const DevicesSettingsView(this.controller, {Key? key}) : super(key: key);
2021-04-15 09:46:43 +02:00
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
2021-10-14 18:09:30 +02:00
leading: const BackButton(),
2022-01-29 12:35:03 +01:00
title: Text(L10n.of(context)!.devices),
2021-04-15 09:46:43 +02:00
),
body: MaxWidthBody(
child: FutureBuilder<bool>(
future: controller.loadUserDevices(context),
builder: (BuildContext context, snapshot) {
if (snapshot.hasError) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
2021-10-14 18:09:30 +02:00
const Icon(Icons.error_outlined),
2021-04-15 09:46:43 +02:00
Text(snapshot.error.toString()),
],
),
);
}
if (!snapshot.hasData || controller.devices == null) {
2021-10-14 18:09:30 +02:00
return const Center(
2021-10-10 13:38:06 +02:00
child: CircularProgressIndicator.adaptive(strokeWidth: 2));
2021-04-15 09:46:43 +02:00
}
return Column(
children: <Widget>[
if (controller.thisDevice != null)
UserDeviceListItem(
2022-01-29 12:35:03 +01:00
controller.thisDevice!,
2021-04-15 09:46:43 +02:00
rename: controller.renameDeviceAction,
remove: (d) => controller.removeDevicesAction([d]),
verify: controller.verifyDeviceAction,
block: controller.blockDeviceAction,
unblock: controller.unblockDeviceAction,
),
2021-10-14 18:09:30 +02:00
const Divider(height: 1),
2021-04-15 09:46:43 +02:00
if (controller.notThisDevice.isNotEmpty)
ListTile(
title: Text(
controller.errorDeletingDevices ??
2022-01-29 12:35:03 +01:00
L10n.of(context)!.removeAllOtherDevices,
2021-10-14 18:09:30 +02:00
style: const TextStyle(color: Colors.red),
2021-04-15 09:46:43 +02:00
),
trailing: controller.loadingDeletingDevices
2021-10-17 14:15:29 +02:00
? const CircularProgressIndicator.adaptive(
strokeWidth: 2)
2021-10-14 18:09:30 +02:00
: const Icon(Icons.delete_outline),
2021-04-15 09:46:43 +02:00
onTap: controller.loadingDeletingDevices
? null
: () => controller
.removeDevicesAction(controller.notThisDevice),
),
2021-10-14 18:09:30 +02:00
const Divider(height: 1),
2021-04-15 09:46:43 +02:00
Expanded(
child: controller.notThisDevice.isEmpty
? Center(
child: Icon(
Icons.devices_other,
size: 60,
color: Theme.of(context).secondaryHeaderColor,
),
)
: ListView.separated(
separatorBuilder: (BuildContext context, int i) =>
2021-10-14 18:09:30 +02:00
const Divider(height: 1),
2021-04-15 09:46:43 +02:00
itemCount: controller.notThisDevice.length,
itemBuilder: (BuildContext context, int i) =>
UserDeviceListItem(
controller.notThisDevice[i],
rename: controller.renameDeviceAction,
remove: (d) => controller.removeDevicesAction([d]),
verify: controller.verifyDeviceAction,
block: controller.blockDeviceAction,
unblock: controller.unblockDeviceAction,
),
),
),
],
);
},
),
),
);
}
}