Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forum e Mapa #21

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.juno">
<application
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" android:required="true" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="true" />
<application
android:label="juno"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
Expand Down Expand Up @@ -30,5 +37,8 @@
<meta-data
android:name="flutterEmbedding"
android:value="2" />

<meta-data
</application>

</manifest>
Binary file added assets/UserForum.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/userPost.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/userPost2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 0 additions & 75 deletions lib/src/screens/EmConstrucao/EmConstrucaoScreen.dart

This file was deleted.

123 changes: 123 additions & 0 deletions lib/src/screens/Forum/CreatePost.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import 'dart:io';
import "package:flutter/cupertino.dart";
import "package:flutter/material.dart";
import '../../models/user.dart';
import 'Post/ForumPost.dart';
import 'package:juno/src/database/dao/user_dao.dart';
import 'package:intl/intl.dart';

class CreatePost extends StatefulWidget {
final int userId;

const CreatePost({Key? key, required this.userId}) : super(key: key);

@override
_CreatePostState createState() => _CreatePostState();
}

class _CreatePostState extends State<CreatePost> {
final TextEditingController titleController = TextEditingController();
final TextEditingController contentController = TextEditingController();
String authorName = ""; // Nome do autor

@override
void initState() {
super.initState();
// Buscar o nome do usuário no banco de dados ao iniciar a tela
getUserInfo();
}

// Função para buscar o nome do usuário no banco de dados
void getUserInfo() async {
try {
User user = await UserDAO.getUserById(widget.userId);
setState(() {
authorName = "${user.nome}"; // Altere conforme a estrutura do seu objeto User
});
} catch (e) {
print("Erro ao buscar informações do usuário: $e");
}
}

// Função para criar uma nova postagem
void criarPostagem() {
if (titleController.text.isNotEmpty && contentController.text.isNotEmpty) {
// obter data e hora atual
DateTime agora = DateTime.now();
String dataHoraAtual = DateFormat('dd/MM/yyyy - HH:mm').format(agora);

ForumPost novaPostagem = ForumPost(
author: authorName, // Usar o nome do autor obtido do banco de dados
date: dataHoraAtual,
content: contentController.text,
);

// Adicione a nova postagem à lista de postagens (que deve ser acessível a partir da tela do fórum)
// forumPosts.add(novaPostagem);

// Navegue de volta para a tela do fórum
Navigator.pop(context, novaPostagem);
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Criar Postagem'),
backgroundColor: Color(0xFF3A0751),
),
body: SingleChildScrollView(
child: Container(
color: Color(0xFFFFFFFF),
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
CircleAvatar(
radius: 80,
backgroundImage: AssetImage('assets/UserForum.png'),
),
SizedBox(height: 16),
Text(
"Autor: $authorName", // Exibir o nome do autor
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Color(0xFF3A0751),
),
),
SizedBox(height: 16),
TextFormField(
controller: titleController,
decoration: InputDecoration(
labelText: 'Título',
labelStyle: TextStyle(
color: Color(0xFF3A0751),
),
),
),
TextFormField(
controller: contentController,
decoration: InputDecoration(
labelText: 'Conteúdo',
labelStyle: TextStyle(
color: Color(0xFF3A0751),
),
),
),
SizedBox(height: 16),
ElevatedButton(
onPressed: criarPostagem,
child: Text('Criar Postagem'),
style: ElevatedButton.styleFrom(
primary: Color(0xFF3A0751),
),
),
],
),
),
),
);
}
}
120 changes: 120 additions & 0 deletions lib/src/screens/Forum/Forum.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import 'package:flutter/material.dart';
import 'CreatePost.dart';
import 'ProfileScreens/ProfileForum.dart';
import 'PostCardForum.dart';
import 'Post/ForumPost.dart';


class ForumScreen extends StatefulWidget {
const ForumScreen({Key? key}) : super(key: key);

@override
_ForumScreenState createState() => _ForumScreenState();
}

class _ForumScreenState extends State<ForumScreen> {
String searchKeyword = '';
List<ForumPost> forumPosts = []; // Corrija o tipo da lista para ForumPost

void removePost(ForumPost post) async {
await ForumPost.deletePost(post);
_loadPosts();
}

@override
void initState() {
super.initState();
_loadPosts();
}

void _loadPosts() async {
List<ForumPost> posts = await ForumPost.getPosts(); // Corrija o tipo da lista para ForumPost
setState(() {
forumPosts = posts;
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Fórum - Juno'),
backgroundColor: Colors.red,
centerTitle: true,
),
body: Container(
color: Color(0xFFFFFFFF),
child: Column(
children: [
Padding(
padding: EdgeInsets.all(16),
child: Row(
children: [
Expanded(
child: TextField(
decoration: InputDecoration(
hintText: 'Pesquisar',
prefixIcon: Icon(Icons.search),
),
onChanged: (value) {
setState(() {
searchKeyword = value;
});
},
),
),
InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ProfileForum(),
),
);
},
child: CircleAvatar(
radius: 25,
backgroundImage: AssetImage('assets/UserForum.png'),
),
),
],
),
),
Expanded(
child: ListView.builder(
itemCount: forumPosts.length,
itemBuilder: (context, index) {
return PostCardForum(
post: forumPosts[index],
onDelete: () {
removePost(forumPosts[index]);
},
);
},
),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () async {
// Navegue para a tela CreatePost e aguarde o resultado
final novaPostagem = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CreatePost(userId: 1,),
),
);

// Se houver uma nova postagem, adicione-a ao banco de dados e recarregue as postagens
if (novaPostagem != null) {
await ForumPost.insertPost(novaPostagem); // Corrija para ForumPost
_loadPosts();
}
},
child: Icon(Icons.add),
backgroundColor: Color(0xFF3A0751),
),
);
}
}
Loading