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

Feat transaction card component #37

Merged
merged 1 commit into from
Nov 7, 2022
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
cache-key: "flutter-:os:-:channel:-:version:-:arch:-:hash:"
cache-path: "${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:"
architecture: x64
- run: flutter build web --release
- run: flutter build web --release --web-renderer html
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
Expand Down
47 changes: 29 additions & 18 deletions lib/components/button_option.dart
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
import 'package:flutter/material.dart';

class ButtonOption extends StatelessWidget {
final Color? color;
final IconData iconData;
final String text;
final Function()? onPressed;
const ButtonOption(
{super.key, required this.iconData, required this.text, this.onPressed});
const ButtonOption({
super.key,
required this.iconData,
required this.text,
this.onPressed,
this.color,
});

@override
Widget build(BuildContext context) {
var isDisabled = onPressed == null;
return SizedBox(
width: 87,
child: InkWell(
onTap: onPressed,
child: Ink(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(iconData, size: 22),
const SizedBox(height: 4),
Text(
text,
style: const TextStyle(
fontWeight: FontWeight.w800,
fontSize: 10,
),
)
],
child: Opacity(
opacity: isDisabled ? 0.5 : 1,
child: InkWell(
onTap: onPressed,
child: Ink(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(iconData, size: 22, color: color),
const SizedBox(height: 4),
Text(
text,
style: TextStyle(
fontWeight: FontWeight.w800,
fontSize: 10,
color: color,
),
)
],
),
),
),
),
Expand Down
244 changes: 244 additions & 0 deletions lib/components/cards/transaction_card.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
import 'package:flutter/material.dart';
import 'package:livrodin/components/button_option.dart';
import 'package:livrodin/components/profile_icon.dart';
import 'package:livrodin/configs/themes.dart';
import 'package:livrodin/models/book.dart';
import 'package:livrodin/models/transaction.dart';
import 'package:livrodin/models/user.dart';
import 'package:intl/intl.dart';

class TransactionCard extends StatelessWidget {
final Transaction transaction;

final Function()? onMessagePressed;
final Function()? onConfirmPressed;
final Function()? onCancelPressed;

const TransactionCard({
super.key,
required this.transaction,
this.onMessagePressed,
this.onConfirmPressed,
this.onCancelPressed,
});

@override
Widget build(BuildContext context) {
return Container(
width: 345,
height: 180,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
spreadRadius: 0,
blurRadius: 4,
offset: const Offset(0, 4), // changes position of shadow
),
],
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
children: [
Expanded(
child: Padding(
padding:
const EdgeInsets.symmetric(vertical: 6.0, horizontal: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
// "Última Atualização: 02 de outubro de 2022 às 15:30",
// make this dynamic
"Última Atualização: ${formatDate(transaction.updatedAt)}",
style: const TextStyle(
fontWeight: FontWeight.w800,
fontSize: 8,
color: grey,
),
),
const SizedBox(
height: 5,
),
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
BookCardWithProfile(
user: transaction.user1,
book: transaction.availability.book,
otherUser: transaction.user2,
),
const Icon(Icons.swap_horizontal_circle),
transaction.type == BookAvailableType.trade
? BookCardWithProfile(
user: transaction.user2,
book: transaction.availability2?.book,
otherUser: transaction.user1,
)
: ProfileCard(
user: transaction.user2,
)
],
),
)
],
),
),
),
// border left
Container(
decoration: const BoxDecoration(
border: Border(
left: BorderSide(
width: 1.0,
color: grey,
),
),
),
child: Padding(
padding: const EdgeInsets.only(top: 13.5, bottom: 13.5),
child: Column(
children: [
ButtonOption(
iconData: Icons.message,
text: "Mensagem",
onPressed:
transaction.status == TransactionStatus.inProgress
? onMessagePressed
: null,
),
const SizedBox(height: 15),
ButtonOption(
iconData: Icons.check_circle,
text: "Confirmar",
color: green,
onPressed: transaction.status == TransactionStatus.pending
? onConfirmPressed
: null,
),
const SizedBox(height: 15),
ButtonOption(
iconData: Icons.cancel,
text: "Cancelar",
color: red,
onPressed: onCancelPressed,
),
],
),
),
)
],
));
}
}

// transform DateTime like this: "Última Atualização: 02 de outubro de 2022 às 15:30"
String formatDate(DateTime date) {
var formatter = DateFormat("dd 'de' MMMM 'de' yyyy 'ás' HH:mm", 'pt_BR');
return formatter.format(date);
}

class ProfileCard extends StatelessWidget {
final User user;
const ProfileCard({super.key, required this.user});

@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ProfileIcon(
size: ProfileSize.lg,
image: user.profilePictureUrl,
),
const SizedBox(height: 10),
Text(
user.name,
style: const TextStyle(
fontWeight: FontWeight.w800,
fontSize: 12,
color: grey,
),
)
],
);
}
}

class BookCardWithProfile extends StatelessWidget {
final Book? book;
final User user;
final User otherUser;
const BookCardWithProfile({
Key? key,
required this.user,
required this.otherUser,
this.book,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return Stack(
clipBehavior: Clip.none,
alignment: Alignment.center,
children: [
Column(
children: [
Container(
height: 125,
width: 87,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(5),
image: book != null
? DecorationImage(
image: NetworkImage(book!.coverUrl!),
fit: BoxFit.cover,
)
: null,
),
child: Visibility(
visible: book == null,
child: Center(
child: Text(
"Aguardando\n${otherUser.name}\nEscolher",
style: const TextStyle(
fontWeight: FontWeight.w600, fontSize: 10, color: grey),
textAlign: TextAlign.center,
),
),
),
),
const SizedBox(
height: 27,
),
],
),
Positioned(
bottom: 0,
child: Column(
children: [
ProfileIcon(
size: ProfileSize.md,
image: user.profilePictureUrl,
),
Text(
user.isMe ? "Eu" : user.name,
style: const TextStyle(
fontWeight: FontWeight.w800,
fontSize: 8,
color: grey,
),
),
],
),
),
],
);
}
}
13 changes: 13 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:livrodin/configs/themes.dart';
import 'package:livrodin/controllers/auth_controller.dart';
import 'package:livrodin/controllers/book_controller.dart';
Expand All @@ -23,6 +25,9 @@ import 'firebase_options.dart';

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();

initializeDateFormatting('pt_BR', null);

await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
Expand All @@ -44,6 +49,14 @@ class MyApp extends StatelessWidget {
theme: themeData,
initialRoute: isLogged ? '/home' : '/login',
defaultTransition: Transition.fade,
scrollBehavior: const MaterialScrollBehavior().copyWith(
dragDevices: {
PointerDeviceKind.mouse,
PointerDeviceKind.touch,
PointerDeviceKind.stylus,
PointerDeviceKind.unknown
},
),
getPages: [
GetPage(
name: '/login',
Expand Down
47 changes: 47 additions & 0 deletions lib/models/transaction.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'package:livrodin/models/availability.dart';
import 'package:livrodin/models/book.dart';
import 'package:livrodin/models/user.dart';

enum TransactionStatus {
pending,
inProgress,
completed,
canceled;

String get value {
switch (this) {
case TransactionStatus.pending:
return "PENDING";
case TransactionStatus.inProgress:
return "IN_PROGRESS";
case TransactionStatus.completed:
return "COMPLETED";
case TransactionStatus.canceled:
return "CANCELED";
}
}
}

class Transaction {
final String id;
final Availability availability;
final Availability? availability2;
final DateTime createdAt;
final DateTime updatedAt;
final BookAvailableType type;
final TransactionStatus status;
final User user1;
final User user2;

Transaction({
required this.id,
required this.availability,
this.availability2,
required this.createdAt,
required this.updatedAt,
required this.type,
required this.status,
required this.user1,
required this.user2,
});
}
Loading