fluffychat/lib/pages/device_settings/device_settings_view.dart

140 lines
5.7 KiB
Dart
Raw Normal View History

2021-04-15 07:46:43 +00:00
import 'package:flutter/material.dart';
2021-10-26 16:50:34 +00:00
2021-04-15 07:46:43 +00:00
import 'package:flutter_gen/gen_l10n/l10n.dart';
2021-11-09 20:32:16 +00:00
import 'package:fluffychat/pages/device_settings/device_settings.dart';
2021-10-26 16:50:34 +00:00
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
2021-11-09 20:32:16 +00:00
import 'user_device_list_item.dart';
2021-04-15 07:46:43 +00:00
2021-05-22 07:13:47 +00:00
class DevicesSettingsView extends StatelessWidget {
2021-04-15 07:46:43 +00:00
final DevicesSettingsController controller;
const DevicesSettingsView(this.controller, {super.key});
2021-04-15 07:46:43 +00:00
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: const Center(child: BackButton()),
2022-01-29 11:35:03 +00:00
title: Text(L10n.of(context)!.devices),
2021-04-15 07:46:43 +00: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 16:09:30 +00:00
const Icon(Icons.error_outlined),
2021-04-15 07:46:43 +00:00
Text(snapshot.error.toString()),
],
),
);
}
if (!snapshot.hasData || controller.devices == null) {
2021-10-14 16:09:30 +00:00
return const Center(
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
);
2021-04-15 07:46:43 +00:00
}
2022-07-07 16:50:13 +00:00
return ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
2022-07-07 16:50:13 +00:00
itemCount: controller.notThisDevice.length + 1,
itemBuilder: (BuildContext context, int i) {
if (i == 0) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
2023-12-26 17:19:33 +00:00
if (controller.thisDevice != null) ...[
Container(
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 8.0,
),
alignment: Alignment.centerLeft,
child: Text(
L10n.of(context)!.thisDevice,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.primary,
),
textAlign: TextAlign.left,
),
),
2022-07-07 16:50:13 +00:00
UserDeviceListItem(
controller.thisDevice!,
rename: controller.renameDeviceAction,
remove: (d) => controller.removeDevicesAction([d]),
verify: controller.verifyDeviceAction,
block: controller.blockDeviceAction,
unblock: controller.unblockDeviceAction,
),
2023-12-26 17:19:33 +00:00
const Divider(
height: 16.0,
indent: 16,
endIndent: 16,
),
],
2022-07-07 16:50:13 +00:00
if (controller.notThisDevice.isNotEmpty)
2023-12-26 17:19:33 +00:00
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 8.0,
),
child: SizedBox(
width: double.infinity,
child: OutlinedButton.icon(
label: Text(
controller.errorDeletingDevices ??
L10n.of(context)!.removeAllOtherDevices,
),
style: OutlinedButton.styleFrom(
foregroundColor:
Theme.of(context).colorScheme.error,
side: BorderSide(
color: Theme.of(context).colorScheme.error,
),
),
icon: controller.loadingDeletingDevices
? const CircularProgressIndicator.adaptive(
strokeWidth: 2,
)
: const Icon(Icons.delete_outline),
onPressed: controller.loadingDeletingDevices
? null
: () => controller.removeDevicesAction(
controller.notThisDevice,
),
),
2021-04-15 07:46:43 +00:00
),
)
else
Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text(L10n.of(context)!.noOtherDevicesFound),
),
2021-04-15 07:46:43 +00:00
),
2022-07-07 16:50:13 +00:00
],
);
}
i--;
return UserDeviceListItem(
controller.notThisDevice[i],
rename: controller.renameDeviceAction,
remove: (d) => controller.removeDevicesAction([d]),
verify: controller.verifyDeviceAction,
block: controller.blockDeviceAction,
unblock: controller.unblockDeviceAction,
);
},
2021-04-15 07:46:43 +00:00
);
},
),
),
);
}
}