Add table creation
This commit is contained in:
parent
09c9549004
commit
4a5039cb19
19 changed files with 1132 additions and 141 deletions
15
lib/pages/home_panels/none_panel.dart
Normal file
15
lib/pages/home_panels/none_panel.dart
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class NonePanel extends StatelessWidget {
|
||||
const NonePanel({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Text(
|
||||
'Use the menu for navigation',
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
36
lib/pages/home_panels/settings_panel.dart
Normal file
36
lib/pages/home_panels/settings_panel.dart
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class SettingsPanel extends StatefulWidget {
|
||||
const SettingsPanel({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _SettingsPanelState();
|
||||
}
|
||||
|
||||
class _SettingsPanelState extends State<SettingsPanel> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SingleChildScrollView(
|
||||
child: IntrinsicHeight(
|
||||
child: _buildBody(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody() {
|
||||
return Column(
|
||||
children: [
|
||||
Text(
|
||||
'Settings',
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
179
lib/pages/home_panels/tables_list_panel.dart
Normal file
179
lib/pages/home_panels/tables_list_panel.dart
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
import 'package:bottom_sheet/bottom_sheet.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';
|
||||
import 'package:tuuli_app/c.dart';
|
||||
import 'package:tuuli_app/pages/bottomsheers/edit_table_bottomsheet.dart';
|
||||
|
||||
class TablesListPanel extends StatefulWidget {
|
||||
final TablesListModel tables;
|
||||
|
||||
const TablesListPanel({super.key, required this.tables});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _TablesListPanelState();
|
||||
}
|
||||
|
||||
class _TablesListPanelState extends State<TablesListPanel> {
|
||||
final apiClient = Get.find<ApiClient>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _buildTableList();
|
||||
}
|
||||
|
||||
Widget _buildTableCard(BuildContext ctx, TableModel table) {
|
||||
return Card(
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: InkWell(
|
||||
onTap: () => _openTable(table),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.all(5),
|
||||
padding: const EdgeInsets.all(5),
|
||||
child: Stack(
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
table.tableName.pascalCase,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
table.system ? "System" : "Userland",
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
"${table.columns.length} column(s)",
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget get newTableCard => Card(
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: InkWell(
|
||||
onTap: _createNewTable,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.all(5),
|
||||
padding: const EdgeInsets.all(5),
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Widget _buildTableList() {
|
||||
var tableItems = widget.tables.tables
|
||||
.where((table) => !table.hidden && !table.system)
|
||||
.toList(growable: false);
|
||||
|
||||
if (tableItems.isEmpty) {
|
||||
return Center(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
"No tables found",
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).disabledColor,
|
||||
fontSize: 24,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
"Maybe create one?",
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).disabledColor,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton.icon(
|
||||
onPressed: _createNewTable,
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text("Create table"),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return GridView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: tableItems.length + 1,
|
||||
itemBuilder: (ctx, i) =>
|
||||
i == 0 ? newTableCard : _buildTableCard(ctx, tableItems[i - 1]),
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 5,
|
||||
childAspectRatio: 5 / 2,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _createNewTable() async {
|
||||
final result = await showFlexibleBottomSheet<EditTableBottomSheetResult>(
|
||||
minHeight: 0,
|
||||
initHeight: 0.75,
|
||||
maxHeight: 1,
|
||||
context: context,
|
||||
builder: (_, __, ___) => const EditTableBottomSheet(),
|
||||
anchors: [0, 0.5, 1],
|
||||
isSafeArea: true,
|
||||
isDismissible: false,
|
||||
);
|
||||
|
||||
if (result == null) return;
|
||||
|
||||
await apiClient
|
||||
.createTable(result.tableName, result.fields)
|
||||
.then((e) => e.unfold((_) {
|
||||
Get.snackbar(
|
||||
"Success",
|
||||
"Table created",
|
||||
colorText: Colors.white,
|
||||
);
|
||||
}, (error) {
|
||||
Get.defaultDialog(
|
||||
title: "Error",
|
||||
middleText: error.toString(),
|
||||
textConfirm: "OK",
|
||||
onConfirm: () => Get.back(),
|
||||
);
|
||||
}));
|
||||
}
|
||||
|
||||
void _openTable(TableModel table) async {
|
||||
// TODO: Open table
|
||||
}
|
||||
}
|
||||
36
lib/pages/home_panels/users_list_panel.dart
Normal file
36
lib/pages/home_panels/users_list_panel.dart
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class UsersListPanel extends StatefulWidget {
|
||||
const UsersListPanel({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _UsersListPanelState();
|
||||
}
|
||||
|
||||
class _UsersListPanelState extends State<UsersListPanel> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SingleChildScrollView(
|
||||
child: IntrinsicHeight(
|
||||
child: _buildBody(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody() {
|
||||
return Column(
|
||||
children: [
|
||||
Text(
|
||||
'Users',
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue