Unverified Commit 5ef5d4ce authored by sxfzn's avatar sxfzn Committed by GitHub

Add files via upload

parent 7e291a8b
This diff is collapsed.
......@@ -2,24 +2,27 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:paperchase_app/book_detail_page.dart';
import 'colors.dart';
class StrictChatPage extends StatefulWidget {
final String chatId;
//final String bookId;
final String otherUserName;
final String currentUserId;
final String sellerId;
final List<String> predefinedMessages;
const StrictChatPage({
Key? key,
super.key,
required this.chatId,
required this.otherUserName,
required this.currentUserId,
required this.sellerId,
}) : super(key: key);
this.predefinedMessages = const [
"Is this still available?",
"When can we meet?",
"I'll take it",
"Thanks!",
"Hello",
"Can you hold it for me?",
"What's your lowest price?",
],
});
@override
_StrictChatPageState createState() => _StrictChatPageState();
......@@ -29,32 +32,6 @@ class _StrictChatPageState extends State<StrictChatPage> {
final ScrollController _scrollController = ScrollController();
final TextEditingController _messageController = TextEditingController();
String? _bookTitle;
String? _bookId;
List<String> get predefinedMessages {
final currentUser = FirebaseAuth.instance.currentUser;
final email = currentUser?.email ?? "your email";
if (widget.currentUserId == widget.sellerId) {
return [
"Yes, it's still available.",
"Thanks!",
"How about we meet this weekend?",
"That a deal!",
"Yes, I will hold it",
"Contact me at $email"
];
} else {
return [
"Is this still available?",
"When can we meet?",
"I'll take it",
"Thanks!",
"Can you hold it for me?",
"Contact me at $email",
];
}
}
@override
void initState() {
......@@ -79,7 +56,6 @@ List<String> get predefinedMessages {
if (doc.exists) {
setState(() {
_bookTitle = doc.data()?['bookTitle'] as String?;
_bookId = doc.data()?['bookId'] as String?;
});
}
} catch (e) {
......@@ -135,8 +111,7 @@ List<String> get predefinedMessages {
final backgroundColor2 = isDarkMode ? kLightBackground : kDarkBackground;
final textColor = isDarkMode ? kDarkText : kLightText;
final textColor2 = isDarkMode ? kLightText : kDarkText;
final messageBackgroundOther = isDarkMode ? Colors.grey[800] : Colors
.grey[200];
final messageBackgroundOther = isDarkMode ? Colors.grey[800] : Colors.grey[200];
return Scaffold(
appBar: AppBar(
......@@ -201,8 +176,7 @@ List<String> get predefinedMessages {
final text = data['message'] as String? ?? '';
final senderId = data['senderId'] as String? ?? '';
final currentUser = FirebaseAuth.instance.currentUser;
final isMe = currentUser != null &&
senderId == currentUser.uid;
final isMe = currentUser != null && senderId == currentUser.uid;
return Container(
margin: const EdgeInsets.symmetric(vertical: 4),
......@@ -213,10 +187,7 @@ List<String> get predefinedMessages {
children: [
Container(
constraints: BoxConstraints(
maxWidth: MediaQuery
.of(context)
.size
.width * 0.75,
maxWidth: MediaQuery.of(context).size.width * 0.75,
),
padding: const EdgeInsets.symmetric(
horizontal: 16,
......@@ -266,57 +237,27 @@ List<String> get predefinedMessages {
fontSize: 14,
),
),
// Only show the Confirmed button if the current user is the seller
if (widget.currentUserId == widget.sellerId)
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () => _confirmAndCompletePurchase(context),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.lightGreenAccent,
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: const Text(
'Confirmed!',
style: TextStyle(fontSize: 18, color: kLightText),
),
),
),
if (widget.currentUserId == widget.sellerId)
const SizedBox(height: 12),
Wrap(
spacing: 12,
runSpacing: 12,
children: predefinedMessages.map((msg) {
children: widget.predefinedMessages.map((msg) {
return ActionChip(
label: Text(msg),
onPressed: () => _sendMessage(msg),
backgroundColor: backgroundColor,
labelStyle: TextStyle(color: textColor,),
labelStyle: TextStyle(
color: textColor,
),
);
}).toList(),
),
const SizedBox(height: 12),
],
),
),
),
],
),
);
}
void _confirmAndCompletePurchase(BuildContext context) async {
await FirebaseFirestore.instance.collection('books').doc(_bookId).delete();
//await FirebaseFirestore.instance.collection('chats').doc(widget.chatId).collection('messages').doc().delete();
await FirebaseFirestore.instance.collection('chats').doc(widget.chatId).delete();
Navigator.pop(context);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Transaction completed!')),
);
}
}
\ No newline at end of file
......@@ -3,6 +3,8 @@ import 'package:firebase_auth/firebase_auth.dart';
import 'colors.dart';
class ForgotPasswordPage extends StatefulWidget {
const ForgotPasswordPage({super.key});
@override
_ForgotPasswordPageState createState() => _ForgotPasswordPageState();
}
......@@ -67,7 +69,6 @@ class _ForgotPasswordPageState extends State<ForgotPasswordPage> {
SizedBox(height: 20),
ElevatedButton(
onPressed: _resetPassword,
child: Text("Reset Password"),
style: ElevatedButton.styleFrom(
backgroundColor: isDarkMode ? kLightBackground : kDarkBackground, // Background color
foregroundColor: isDarkMode ? kDarkBackground : kLightBackground, // Text color
......@@ -76,6 +77,7 @@ class _ForgotPasswordPageState extends State<ForgotPasswordPage> {
borderRadius: BorderRadius.circular(10), // Rounded corners
),
),
child: Text("Reset Password"),
),
],
),
......
This diff is collapsed.
......@@ -97,7 +97,7 @@ class _LoginPageState extends State<LoginPage> {
_isLoading
? const CircularProgressIndicator()
: ElevatedButton(
onPressed: _login, child: const Text('Login'),
onPressed: _login,
style: ElevatedButton.styleFrom(
backgroundColor: isDarkMode ? kLightBackground : kDarkBackground, // Background color
foregroundColor: isDarkMode ? kDarkBackground : kLightBackground, // Text color
......@@ -105,7 +105,7 @@ class _LoginPageState extends State<LoginPage> {
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10), // Rounded corners
),
),
), child: const Text('Login'),
),
TextButton(
style: TextButton.styleFrom(
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -6,10 +6,10 @@ class SettingsPage extends StatefulWidget {
final VoidCallback toggleTheme;
const SettingsPage({
Key? key,
super.key,
required this.isDarkMode,
required this.toggleTheme,
}) : super(key: key);
});
@override
State<SettingsPage> createState() => _SettingsPageState();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment