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'; ...@@ -2,24 +2,27 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_auth/firebase_auth.dart';
import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:paperchase_app/book_detail_page.dart';
import 'colors.dart'; import 'colors.dart';
class StrictChatPage extends StatefulWidget { class StrictChatPage extends StatefulWidget {
final String chatId; final String chatId;
//final String bookId;
final String otherUserName; final String otherUserName;
final String currentUserId; final List<String> predefinedMessages;
final String sellerId;
const StrictChatPage({ const StrictChatPage({
Key? key, super.key,
required this.chatId, required this.chatId,
required this.otherUserName, required this.otherUserName,
required this.currentUserId, this.predefinedMessages = const [
required this.sellerId, "Is this still available?",
}) : super(key: key); "When can we meet?",
"I'll take it",
"Thanks!",
"Hello",
"Can you hold it for me?",
"What's your lowest price?",
],
});
@override @override
_StrictChatPageState createState() => _StrictChatPageState(); _StrictChatPageState createState() => _StrictChatPageState();
...@@ -29,32 +32,6 @@ class _StrictChatPageState extends State<StrictChatPage> { ...@@ -29,32 +32,6 @@ class _StrictChatPageState extends State<StrictChatPage> {
final ScrollController _scrollController = ScrollController(); final ScrollController _scrollController = ScrollController();
final TextEditingController _messageController = TextEditingController(); final TextEditingController _messageController = TextEditingController();
String? _bookTitle; 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 @override
void initState() { void initState() {
...@@ -79,7 +56,6 @@ List<String> get predefinedMessages { ...@@ -79,7 +56,6 @@ List<String> get predefinedMessages {
if (doc.exists) { if (doc.exists) {
setState(() { setState(() {
_bookTitle = doc.data()?['bookTitle'] as String?; _bookTitle = doc.data()?['bookTitle'] as String?;
_bookId = doc.data()?['bookId'] as String?;
}); });
} }
} catch (e) { } catch (e) {
...@@ -135,8 +111,7 @@ List<String> get predefinedMessages { ...@@ -135,8 +111,7 @@ List<String> get predefinedMessages {
final backgroundColor2 = isDarkMode ? kLightBackground : kDarkBackground; final backgroundColor2 = isDarkMode ? kLightBackground : kDarkBackground;
final textColor = isDarkMode ? kDarkText : kLightText; final textColor = isDarkMode ? kDarkText : kLightText;
final textColor2 = isDarkMode ? kLightText : kDarkText; final textColor2 = isDarkMode ? kLightText : kDarkText;
final messageBackgroundOther = isDarkMode ? Colors.grey[800] : Colors final messageBackgroundOther = isDarkMode ? Colors.grey[800] : Colors.grey[200];
.grey[200];
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
...@@ -201,8 +176,7 @@ List<String> get predefinedMessages { ...@@ -201,8 +176,7 @@ List<String> get predefinedMessages {
final text = data['message'] as String? ?? ''; final text = data['message'] as String? ?? '';
final senderId = data['senderId'] as String? ?? ''; final senderId = data['senderId'] as String? ?? '';
final currentUser = FirebaseAuth.instance.currentUser; final currentUser = FirebaseAuth.instance.currentUser;
final isMe = currentUser != null && final isMe = currentUser != null && senderId == currentUser.uid;
senderId == currentUser.uid;
return Container( return Container(
margin: const EdgeInsets.symmetric(vertical: 4), margin: const EdgeInsets.symmetric(vertical: 4),
...@@ -213,10 +187,7 @@ List<String> get predefinedMessages { ...@@ -213,10 +187,7 @@ List<String> get predefinedMessages {
children: [ children: [
Container( Container(
constraints: BoxConstraints( constraints: BoxConstraints(
maxWidth: MediaQuery maxWidth: MediaQuery.of(context).size.width * 0.75,
.of(context)
.size
.width * 0.75,
), ),
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
horizontal: 16, horizontal: 16,
...@@ -266,57 +237,27 @@ List<String> get predefinedMessages { ...@@ -266,57 +237,27 @@ List<String> get predefinedMessages {
fontSize: 14, 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), const SizedBox(height: 12),
Wrap( Wrap(
spacing: 12, spacing: 12,
runSpacing: 12, runSpacing: 12,
children: predefinedMessages.map((msg) { children: widget.predefinedMessages.map((msg) {
return ActionChip( return ActionChip(
label: Text(msg), label: Text(msg),
onPressed: () => _sendMessage(msg), onPressed: () => _sendMessage(msg),
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
labelStyle: TextStyle(color: textColor,), labelStyle: TextStyle(
color: textColor,
),
); );
}).toList(), }).toList(),
), ),
const SizedBox(height: 12), 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'; ...@@ -3,6 +3,8 @@ import 'package:firebase_auth/firebase_auth.dart';
import 'colors.dart'; import 'colors.dart';
class ForgotPasswordPage extends StatefulWidget { class ForgotPasswordPage extends StatefulWidget {
const ForgotPasswordPage({super.key});
@override @override
_ForgotPasswordPageState createState() => _ForgotPasswordPageState(); _ForgotPasswordPageState createState() => _ForgotPasswordPageState();
} }
...@@ -67,7 +69,6 @@ class _ForgotPasswordPageState extends State<ForgotPasswordPage> { ...@@ -67,7 +69,6 @@ class _ForgotPasswordPageState extends State<ForgotPasswordPage> {
SizedBox(height: 20), SizedBox(height: 20),
ElevatedButton( ElevatedButton(
onPressed: _resetPassword, onPressed: _resetPassword,
child: Text("Reset Password"),
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: isDarkMode ? kLightBackground : kDarkBackground, // Background color backgroundColor: isDarkMode ? kLightBackground : kDarkBackground, // Background color
foregroundColor: isDarkMode ? kDarkBackground : kLightBackground, // Text color foregroundColor: isDarkMode ? kDarkBackground : kLightBackground, // Text color
...@@ -76,6 +77,7 @@ class _ForgotPasswordPageState extends State<ForgotPasswordPage> { ...@@ -76,6 +77,7 @@ class _ForgotPasswordPageState extends State<ForgotPasswordPage> {
borderRadius: BorderRadius.circular(10), // Rounded corners borderRadius: BorderRadius.circular(10), // Rounded corners
), ),
), ),
child: Text("Reset Password"),
), ),
], ],
), ),
......
This diff is collapsed.
...@@ -97,7 +97,7 @@ class _LoginPageState extends State<LoginPage> { ...@@ -97,7 +97,7 @@ class _LoginPageState extends State<LoginPage> {
_isLoading _isLoading
? const CircularProgressIndicator() ? const CircularProgressIndicator()
: ElevatedButton( : ElevatedButton(
onPressed: _login, child: const Text('Login'), onPressed: _login,
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: isDarkMode ? kLightBackground : kDarkBackground, // Background color backgroundColor: isDarkMode ? kLightBackground : kDarkBackground, // Background color
foregroundColor: isDarkMode ? kDarkBackground : kLightBackground, // Text color foregroundColor: isDarkMode ? kDarkBackground : kLightBackground, // Text color
...@@ -105,7 +105,7 @@ class _LoginPageState extends State<LoginPage> { ...@@ -105,7 +105,7 @@ class _LoginPageState extends State<LoginPage> {
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10), // Rounded corners borderRadius: BorderRadius.circular(10), // Rounded corners
), ),
), ), child: const Text('Login'),
), ),
TextButton( TextButton(
style: TextButton.styleFrom( 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 { ...@@ -6,10 +6,10 @@ class SettingsPage extends StatefulWidget {
final VoidCallback toggleTheme; final VoidCallback toggleTheme;
const SettingsPage({ const SettingsPage({
Key? key, super.key,
required this.isDarkMode, required this.isDarkMode,
required this.toggleTheme, required this.toggleTheme,
}) : super(key: key); });
@override @override
State<SettingsPage> createState() => _SettingsPageState(); 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