MVP II (Criação de conta funcional)
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
|
import 'dart:io';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:image_picker/image_picker.dart';
|
||||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||||
import '../constants/item_categories.dart';
|
import '../constants/item_categories.dart';
|
||||||
import '../theme/app_theme.dart';
|
import '../theme/app_theme.dart';
|
||||||
@@ -661,6 +663,7 @@ class ItemDetailScreen extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final cat = categoryById(item['categoria'] as String?);
|
final cat = categoryById(item['categoria'] as String?);
|
||||||
final tags = List<String>.from(item['tags'] ?? []);
|
final tags = List<String>.from(item['tags'] ?? []);
|
||||||
|
final notes = item['nota'] ?? item['notes'];
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: AppColors.background,
|
backgroundColor: AppColors.background,
|
||||||
@@ -783,6 +786,24 @@ class ItemDetailScreen extends StatelessWidget {
|
|||||||
.toList(),
|
.toList(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
if (notes != null && notes.toString().isNotEmpty) ...[
|
||||||
|
const Text('Notas', style: AppText.label),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Container(
|
||||||
|
width: double.infinity,
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: AppColors.surface,
|
||||||
|
borderRadius: BorderRadius.circular(AppRadius.lg),
|
||||||
|
border: Border.all(color: AppColors.border),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
notes.toString(),
|
||||||
|
style: AppText.body.copyWith(height: 1.4),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -806,27 +827,126 @@ class EditItemScreen extends StatefulWidget {
|
|||||||
|
|
||||||
class _EditItemScreenState extends State<EditItemScreen> {
|
class _EditItemScreenState extends State<EditItemScreen> {
|
||||||
late TextEditingController _nameController;
|
late TextEditingController _nameController;
|
||||||
|
late TextEditingController _notesController;
|
||||||
ItemCategory? _selectedCategory;
|
ItemCategory? _selectedCategory;
|
||||||
final Set<String> _selectedTags = {};
|
final Set<String> _selectedTags = {};
|
||||||
|
final _imagePicker = ImagePicker();
|
||||||
|
XFile? _pickedImage;
|
||||||
|
String? _currentImageUrl;
|
||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_nameController = TextEditingController(text: widget.item['nome'] ?? '');
|
_nameController = TextEditingController(text: widget.item['nome'] ?? '');
|
||||||
|
_notesController = TextEditingController(
|
||||||
|
text: widget.item['nota'] ?? widget.item['notes'] ?? '',
|
||||||
|
);
|
||||||
final catId = widget.item['categoria'] as String?;
|
final catId = widget.item['categoria'] as String?;
|
||||||
if (catId != null) {
|
if (catId != null) {
|
||||||
_selectedCategory = categoryById(catId);
|
_selectedCategory = categoryById(catId);
|
||||||
}
|
}
|
||||||
_selectedTags.addAll(List<String>.from(widget.item['tags'] ?? []));
|
_selectedTags.addAll(List<String>.from(widget.item['tags'] ?? []));
|
||||||
|
final images = widget.item['item_images'] as List?;
|
||||||
|
if (images != null && images.isNotEmpty) {
|
||||||
|
_currentImageUrl = images.first['image_url'] as String?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_nameController.dispose();
|
_nameController.dispose();
|
||||||
|
_notesController.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _pickImage() async {
|
||||||
|
try {
|
||||||
|
final image = await _imagePicker.pickImage(
|
||||||
|
source: ImageSource.gallery,
|
||||||
|
maxWidth: 1080,
|
||||||
|
maxHeight: 1080,
|
||||||
|
imageQuality: 80,
|
||||||
|
);
|
||||||
|
if (image != null) {
|
||||||
|
setState(() => _pickedImage = image);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (mounted) AppSnack.error(context, 'Erro ao selecionar foto: \$e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _takePhoto() async {
|
||||||
|
try {
|
||||||
|
final image = await _imagePicker.pickImage(
|
||||||
|
source: ImageSource.camera,
|
||||||
|
maxWidth: 1080,
|
||||||
|
maxHeight: 1080,
|
||||||
|
imageQuality: 80,
|
||||||
|
);
|
||||||
|
if (image != null) {
|
||||||
|
setState(() => _pickedImage = image);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (mounted) AppSnack.error(context, 'Erro ao abrir câmara: \$e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _showImageOptions() {
|
||||||
|
showModalBottomSheet(
|
||||||
|
context: context,
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.vertical(top: Radius.circular(AppRadius.xl)),
|
||||||
|
),
|
||||||
|
builder: (ctx) => SafeArea(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 20),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text('Alterar foto', style: AppText.h3),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.photo_library_outlined),
|
||||||
|
title: const Text('Galeria'),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.pop(ctx);
|
||||||
|
_pickImage();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.camera_alt_outlined),
|
||||||
|
title: const Text('Câmara'),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.pop(ctx);
|
||||||
|
_takePhoto();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
if (_currentImageUrl != null || _pickedImage != null)
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(
|
||||||
|
Icons.delete_outline,
|
||||||
|
color: AppColors.error,
|
||||||
|
),
|
||||||
|
title: Text(
|
||||||
|
'Remover foto',
|
||||||
|
style: TextStyle(color: AppColors.error),
|
||||||
|
),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.pop(ctx);
|
||||||
|
setState(() {
|
||||||
|
_pickedImage = null;
|
||||||
|
_currentImageUrl = null;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _save() async {
|
Future<void> _save() async {
|
||||||
if (_nameController.text.trim().isEmpty) {
|
if (_nameController.text.trim().isEmpty) {
|
||||||
AppSnack.error(context, 'Nome não pode ser vazio');
|
AppSnack.error(context, 'Nome não pode ser vazio');
|
||||||
@@ -840,8 +960,28 @@ class _EditItemScreenState extends State<EditItemScreen> {
|
|||||||
'nome': _nameController.text.trim(),
|
'nome': _nameController.text.trim(),
|
||||||
'categoria': _selectedCategory?.id,
|
'categoria': _selectedCategory?.id,
|
||||||
'tags': _selectedTags.toList(),
|
'tags': _selectedTags.toList(),
|
||||||
|
'nota': _notesController.text.trim().isEmpty
|
||||||
|
? null
|
||||||
|
: _notesController.text.trim(),
|
||||||
})
|
})
|
||||||
.eq('id', widget.item['id']);
|
.eq('id', widget.item['id']);
|
||||||
|
|
||||||
|
if (_pickedImage != null) {
|
||||||
|
final file = File(_pickedImage!.path);
|
||||||
|
final fileName =
|
||||||
|
'item_${widget.item['id']}_${DateTime.now().millisecondsSinceEpoch}.jpg';
|
||||||
|
await Supabase.instance.client.storage
|
||||||
|
.from('avatars')
|
||||||
|
.upload(fileName, file);
|
||||||
|
final imageUrl = Supabase.instance.client.storage
|
||||||
|
.from('avatars')
|
||||||
|
.getPublicUrl(fileName);
|
||||||
|
await Supabase.instance.client.from('item_images').insert({
|
||||||
|
'item_id': widget.item['id'],
|
||||||
|
'image_url': imageUrl,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
AppSnack.success(context, 'Item atualizado!');
|
AppSnack.success(context, 'Item atualizado!');
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
@@ -868,6 +1008,83 @@ class _EditItemScreenState extends State<EditItemScreen> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
|
// Foto do item
|
||||||
|
Center(
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: _showImageOptions,
|
||||||
|
child: Container(
|
||||||
|
width: 140,
|
||||||
|
height: 140,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: AppColors.surface,
|
||||||
|
borderRadius: BorderRadius.circular(AppRadius.lg),
|
||||||
|
border: Border.all(color: AppColors.border),
|
||||||
|
image: _pickedImage != null
|
||||||
|
? DecorationImage(
|
||||||
|
image: FileImage(File(_pickedImage!.path)),
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
)
|
||||||
|
: _currentImageUrl != null
|
||||||
|
? DecorationImage(
|
||||||
|
image: NetworkImage(_currentImageUrl!),
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
child: _pickedImage == null && _currentImageUrl == null
|
||||||
|
? Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.add_photo_alternate_outlined,
|
||||||
|
size: 40,
|
||||||
|
color: AppColors.textSecondary,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
'Adicionar foto',
|
||||||
|
style: AppText.caption.copyWith(
|
||||||
|
color: AppColors.textSecondary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
: Stack(
|
||||||
|
alignment: Alignment.bottomRight,
|
||||||
|
children: [
|
||||||
|
Positioned(
|
||||||
|
bottom: 8,
|
||||||
|
right: 8,
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.black54,
|
||||||
|
borderRadius: BorderRadius.circular(
|
||||||
|
AppRadius.md,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: const Icon(
|
||||||
|
Icons.edit,
|
||||||
|
color: Colors.white,
|
||||||
|
size: 18,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
Center(
|
||||||
|
child: TextButton.icon(
|
||||||
|
onPressed: _showImageOptions,
|
||||||
|
icon: const Icon(Icons.camera_alt_outlined, size: 18),
|
||||||
|
label: const Text('Alterar foto'),
|
||||||
|
style: TextButton.styleFrom(foregroundColor: AppColors.primary),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 24),
|
||||||
const Text('Nome', style: AppText.label),
|
const Text('Nome', style: AppText.label),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Container(
|
Container(
|
||||||
@@ -886,6 +1103,25 @@ class _EditItemScreenState extends State<EditItemScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
|
const Text('Notas / Descrição', style: AppText.label),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Container(
|
||||||
|
decoration: AppDecorations.outlined(),
|
||||||
|
child: TextField(
|
||||||
|
controller: _notesController,
|
||||||
|
style: AppText.body,
|
||||||
|
maxLines: 3,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
border: InputBorder.none,
|
||||||
|
contentPadding: EdgeInsets.symmetric(
|
||||||
|
horizontal: 16,
|
||||||
|
vertical: 14,
|
||||||
|
),
|
||||||
|
hintText: 'Detalhes, tamanho, cor, localização...',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
const Text('Categoria', style: AppText.label),
|
const Text('Categoria', style: AppText.label),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Wrap(
|
Wrap(
|
||||||
|
|||||||
@@ -270,14 +270,21 @@ class _LoginScreenState extends State<LoginScreen>
|
|||||||
data: {'username': username},
|
data: {'username': username},
|
||||||
);
|
);
|
||||||
if (response.user != null) {
|
if (response.user != null) {
|
||||||
await Supabase.instance.client.from('users').insert({
|
try {
|
||||||
'id': response.user!.id,
|
await Supabase.instance.client.from('users').insert({
|
||||||
'nome': username,
|
'id': response.user!.id,
|
||||||
'email': email,
|
'nome': username,
|
||||||
});
|
});
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
AppSnack.success(context, 'Conta criada com sucesso!');
|
AppSnack.success(context, 'Conta criada com sucesso!');
|
||||||
setState(() => _isLogin = true);
|
setState(() => _isLogin = true);
|
||||||
|
}
|
||||||
|
} catch (dbError) {
|
||||||
|
// Se falhar a inserção na tabela users, ainda permite o login
|
||||||
|
if (mounted) {
|
||||||
|
AppSnack.success(context, 'Conta criada com sucesso!');
|
||||||
|
setState(() => _isLogin = true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} on AuthException catch (e) {
|
} on AuthException catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user