mirror of
https://github.com/madari-media/madari-oss.git
synced 2026-04-19 04:52:03 +00:00
208 lines
5.8 KiB
Dart
208 lines
5.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:madari_client/engine/connection_type.dart';
|
|
import 'package:pocketbase/pocketbase.dart';
|
|
|
|
class CreateNewConnection extends StatefulWidget {
|
|
final void Function(ConnectionTypeRecord record)? onCallback;
|
|
|
|
const CreateNewConnection({
|
|
super.key,
|
|
this.onCallback,
|
|
});
|
|
|
|
@override
|
|
State<CreateNewConnection> createState() => _CreateNewConnectionState();
|
|
}
|
|
|
|
class _CreateNewConnectionState extends State<CreateNewConnection> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
constraints: BoxConstraints(
|
|
maxHeight: MediaQuery.of(context).size.height * 0.85,
|
|
minHeight: MediaQuery.of(context).size.height * 0.5,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context).colorScheme.surface,
|
|
borderRadius: const BorderRadius.vertical(top: Radius.circular(28)),
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
_buildBottomSheetHandle(),
|
|
_buildHeader(context),
|
|
Expanded(
|
|
child: Consumer(
|
|
builder: (context, ref, child) {
|
|
final activity = ref.watch(connectionTypeListProvider(page: 1));
|
|
|
|
return activity.when(
|
|
data: (result) => _buildConnectionList(result),
|
|
error: (error, trace) => _buildError(error),
|
|
loading: () => const Center(
|
|
child: CircularProgressIndicator(),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildBottomSheetHandle() {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(top: 12, bottom: 8),
|
|
child: Container(
|
|
width: 32,
|
|
height: 4,
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey[300],
|
|
borderRadius: BorderRadius.circular(2),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildHeader(BuildContext context) {
|
|
return Container(
|
|
padding: const EdgeInsets.fromLTRB(24, 8, 24, 16),
|
|
child: Column(
|
|
children: [
|
|
Text(
|
|
"Add New Connection",
|
|
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
"Select a connection type to configure",
|
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
color: Colors.grey[600],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildConnectionList(ResultList<ConnectionTypeRecord> result) {
|
|
return ListView.builder(
|
|
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
|
|
itemCount: result.items.length,
|
|
itemBuilder: (context, index) => _buildConnectionTile(
|
|
context,
|
|
result.items[index],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildConnectionTile(BuildContext context, ConnectionTypeRecord item) {
|
|
return InkWell(
|
|
onTap: () {
|
|
final callback = widget.onCallback;
|
|
|
|
if (callback != null) {
|
|
callback(item);
|
|
}
|
|
},
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context).colorScheme.surface,
|
|
border: Border.all(
|
|
color: Colors.grey[200]!,
|
|
width: 1,
|
|
),
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context)
|
|
.colorScheme
|
|
.primaryContainer
|
|
.withOpacity(0.2),
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: Icon(
|
|
getIcon(item.icon),
|
|
color: Theme.of(context).colorScheme.primary,
|
|
size: 24,
|
|
),
|
|
),
|
|
const SizedBox(width: 16),
|
|
Expanded(
|
|
child: Text(
|
|
item.title,
|
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
),
|
|
Icon(
|
|
Icons.chevron_right,
|
|
color: Colors.grey[400],
|
|
size: 20,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildError(Object error) {
|
|
return Padding(
|
|
padding: const EdgeInsets.all(24),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(
|
|
Icons.error_outline,
|
|
size: 48,
|
|
color: Colors.red[300],
|
|
),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
'Unable to load connection types',
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.grey[800],
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
'Please try again later',
|
|
style: TextStyle(color: Colors.grey[600]),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
IconData getIcon(String input) {
|
|
switch (input) {
|
|
case "drive_file_move":
|
|
return Icons.drive_file_move;
|
|
case "sensors_rounded":
|
|
return Icons.sensors_rounded;
|
|
case "telegram":
|
|
return Icons.telegram;
|
|
case "video":
|
|
return Icons.stream;
|
|
default:
|
|
return Icons.ac_unit;
|
|
}
|
|
}
|
|
}
|