73 lines
2 KiB
Dart
73 lines
2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:recase/recase.dart';
|
|
import 'package:tuuli_app/api/api_client.dart';
|
|
import 'package:tuuli_app/api/model/tables_list_model.dart';
|
|
|
|
class OpenTableBottomSheet extends StatefulWidget {
|
|
final TableModel table;
|
|
|
|
const OpenTableBottomSheet({super.key, required this.table});
|
|
|
|
@override
|
|
State<StatefulWidget> createState() => _OpenTableBottomSheetState();
|
|
}
|
|
|
|
class _OpenTableBottomSheetState extends State<OpenTableBottomSheet> {
|
|
final apiClient = Get.find<ApiClient>();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SingleChildScrollView(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Text(
|
|
widget.table.tableName.pascalCase,
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
|
),
|
|
const Spacer(),
|
|
IconButton(
|
|
onPressed: _dropTable,
|
|
icon: const Icon(Icons.delete),
|
|
),
|
|
IconButton(
|
|
onPressed: Get.back,
|
|
icon: const Icon(Icons.cancel),
|
|
),
|
|
],
|
|
),
|
|
const Divider(),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _dropTable() async {
|
|
final really = await Get.defaultDialog<bool>(
|
|
title: "Drop table",
|
|
middleText:
|
|
"Are you sure you want to drop this table \"${widget.table.tableName}\"?",
|
|
textConfirm: "Drop",
|
|
onConfirm: () => Get.back(result: true),
|
|
onCancel: () => Get.back(result: false),
|
|
barrierDismissible: false,
|
|
);
|
|
|
|
if (really != true) {
|
|
return;
|
|
}
|
|
|
|
final result = await apiClient.dropTable(widget.table.tableName);
|
|
result.unfold((data) {
|
|
Get.back();
|
|
}, (error) {
|
|
Get.snackbar("Error", error.toString());
|
|
});
|
|
}
|
|
}
|