Table dropping implemented
This commit is contained in:
parent
529ec239d1
commit
d973954a75
4 changed files with 114 additions and 4 deletions
73
lib/pages/bottomsheets/open_table_bottomsheet.dart
Normal file
73
lib/pages/bottomsheets/open_table_bottomsheet.dart
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
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());
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue