Skip to content

Commit

Permalink
Merge pull request #146 from just-ary27/main
Browse files Browse the repository at this point in the history
  • Loading branch information
fredfalcon committed Dec 15, 2022
2 parents 97d64e2 + 0ec3869 commit 0a8fbdb
Show file tree
Hide file tree
Showing 17 changed files with 331 additions and 141 deletions.
5 changes: 3 additions & 2 deletions lib/src/components/appbar.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:bugheist/src/components/searchbar.dart';
import 'package:bugheist/src/routes/routing.dart';
import 'package:flutter/material.dart';

import '../routes/routing.dart';
import '../components/searchbar.dart';

/// The app's main Appbar
AppBar buildAppBar({required BuildContext context}) {
return AppBar(
Expand Down
144 changes: 99 additions & 45 deletions lib/src/components/issue_intro_card.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:bugheist/src/routes/routing.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

import '../routes/routing.dart';
import '../models/issue_model.dart';
import '../components/issuelike.dart';

/// The card used to display issues in the list of issues on the Issue Page.
class IssueCard extends StatelessWidget {
Expand Down Expand Up @@ -35,67 +36,120 @@ class IssueCard extends StatelessWidget {
children: <Widget>[
Container(
width: size.width,
height: 0.2 * size.height,
height: 0.214 * size.height,
child: Image.network(
issue.screenshotLink!,
issue.screenshotsLink![0],
fit: BoxFit.fill,
),
),
Container(
width: size.width,
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
padding: const EdgeInsets.only(top: 12),
child: Text(
"Issue #${issue.id}",
overflow: TextOverflow.ellipsis,
softWrap: true,
style: GoogleFonts.ubuntu(
textStyle: TextStyle(
color: Color(0xFFDC4654),
fontSize: 17.5,
height: 0.12 * size.height,
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 12,
),
child: ListTile(
// contentPadding: EdgeInsets.zero,
isThreeLine: true,
title: Text(
"Issue #${issue.id}",
overflow: TextOverflow.ellipsis,
softWrap: true,
style: GoogleFonts.ubuntu(
textStyle: TextStyle(
color: Color(0xFFDC4654),
fontSize: 17.5,
),
fontWeight: FontWeight.bold,
),
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.only(top: 8, bottom: 12),
child: Text(
issue.description.replaceAll("\n", " "),
overflow: TextOverflow.ellipsis,
softWrap: true,
style: GoogleFonts.aBeeZee(
textStyle: TextStyle(
fontSize: 12,
color: Color(0xFF737373),
),
),
fontWeight: FontWeight.bold,
),
),
),
Container(
padding: const EdgeInsets.only(top: 8, bottom: 12),
child: Text(
issue.description.replaceAll("\n", " "),
Text(
issue.created_date,
overflow: TextOverflow.ellipsis,
softWrap: true,
style: GoogleFonts.aBeeZee(
textStyle: TextStyle(
fontSize: 12,
color: Color(0xFF737373),
fontSize: 10,
color: Color(0xFFA3A3A3),
),
),
),
),
Row(
children: [
Container(
padding: const EdgeInsets.only(bottom: 12),
child: Text(
issue.created_date,
overflow: TextOverflow.ellipsis,
softWrap: true,
style: GoogleFonts.aBeeZee(
textStyle: TextStyle(
fontSize: 10,
color: Color(0xFFA3A3A3),
),
),
),
),
],
),
],
],
),
trailing: IssueLikeButton(
issue: issue,
),
),
// child: Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: <Widget>[
// Container(
// padding: const EdgeInsets.only(top: 12),
// child: Text(
// "Issue #${issue.id}",
// overflow: TextOverflow.ellipsis,
// softWrap: true,
// style: GoogleFonts.ubuntu(
// textStyle: TextStyle(
// color: Color(0xFFDC4654),
// fontSize: 17.5,
// ),
// fontWeight: FontWeight.bold,
// ),
// ),
// ),
// Container(
// padding: const EdgeInsets.only(top: 8, bottom: 12),
// child: Text(
// issue.description.replaceAll("\n", " "),
// overflow: TextOverflow.ellipsis,
// softWrap: true,
// style: GoogleFonts.aBeeZee(
// textStyle: TextStyle(
// fontSize: 12,
// color: Color(0xFF737373),
// ),
// ),
// ),
// ),
// Row(
// children: [
// Container(
// padding: const EdgeInsets.only(bottom: 12),
// child: Text(
// issue.created_date,
// overflow: TextOverflow.ellipsis,
// softWrap: true,
// style: GoogleFonts.aBeeZee(
// textStyle: TextStyle(
// fontSize: 10,
// color: Color(0xFFA3A3A3),
// ),
// ),
// ),
// ),
// ],
// ),
// ],
// ),
)
],
),
Expand Down
81 changes: 69 additions & 12 deletions lib/src/components/issueflag.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,86 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../models/issue_model.dart';
import '../providers/login_provider.dart';
import '../util/api/issues_api.dart';
import '../util/enums/login_type.dart';

/// Issue flags show and toggle component.
class IssueFlagButton extends ConsumerStatefulWidget {
const IssueFlagButton({Key? key}) : super(key: key);
final Issue issue;
final Color? color;
const IssueFlagButton({
Key? key,
this.color,
required this.issue,
}) : super(key: key);

@override
ConsumerState<ConsumerStatefulWidget> createState() =>
_IssueFlagButtonState();
}

class _IssueFlagButtonState extends ConsumerState<IssueFlagButton> {
late int flags;
late bool flagged;

Future<void> toggleIssueFlag() async {
setState(() {
if (flagged) {
flags = flags - 1;
} else {
flags = flags + 1;
}
flagged = !flagged;
});

try {
bool status = await IssueApiClient.toggleIssueLikes(widget.issue.id!);
if (!status) {
setState(() {
flags = widget.issue.flags!;
flagged = widget.issue.flagged!;
});
} else {
widget.issue.likes = flags;
widget.issue.flagged = flagged;
}
} catch (e) {
print(e);
}
}

@override
void initState() {
super.initState();
flagged = widget.issue.flagged!;
flags = widget.issue.flags!;
}

@override
Widget build(BuildContext context) {
return Container(
width: 25,
child: Row(
children: [
IconButton(
onPressed: () {},
icon: Icon(
Icons.bookmark,
return TextButton.icon(
onPressed: () async {
if (ref.read(loginProvider.notifier).loginType == LoginType.guest) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Login to like and flag issues!"),
),
),
Text(""),
],
);
} else {
await toggleIssueFlag();
}
},
icon: Icon(
Icons.flag_outlined,
color: widget.color,
),
label: Text(
"${flags}",
style: TextStyle(
color: widget.color,
),
),
);
}
Expand Down
82 changes: 70 additions & 12 deletions lib/src/components/issuelike.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,87 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../models/issue_model.dart';
import '../util/api/issues_api.dart';
import '../util/enums/login_type.dart';
import '../providers/login_provider.dart';

/// Issue likes show and toggle component.
class IssueLikeButton extends ConsumerStatefulWidget {
const IssueLikeButton({Key? key}) : super(key: key);
final Issue issue;
final Color? color;

const IssueLikeButton({
Key? key,
required this.issue,
this.color,
}) : super(key: key);

@override
ConsumerState<ConsumerStatefulWidget> createState() =>
_IssueLikeButtonState();
}

class _IssueLikeButtonState extends ConsumerState<IssueLikeButton> {
late int likes;
late bool liked;

Future<void> toggleIssueLike() async {
setState(() {
if (liked) {
likes = likes - 1;
} else {
likes = likes + 1;
}
liked = !liked;
});

try {
bool status = await IssueApiClient.toggleIssueLikes(widget.issue.id!);
if (!status) {
setState(() {
likes = widget.issue.likes!;
liked = widget.issue.liked!;
});
} else {
widget.issue.likes = likes;
widget.issue.liked = liked;
}
} catch (e) {
print(e);
}
}

@override
void initState() {
super.initState();
liked = widget.issue.liked!;
likes = widget.issue.likes!;
}

@override
Widget build(BuildContext context) {
return Container(
width: 25,
child: Row(
children: [
IconButton(
onPressed: () {},
icon: Icon(
Icons.favorite,
return TextButton.icon(
onPressed: () async {
if (ref.read(loginProvider.notifier).loginType == LoginType.guest) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Login to like and flag issues!"),
),
),
Text(""),
],
);
} else {
await toggleIssueLike();
}
},
icon: Icon(
(liked) ? Icons.favorite : Icons.favorite_border_rounded,
color: widget.color,
),
label: Text(
"$likes",
style: TextStyle(
color: widget.color,
),
),
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/components/searchbar.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:bugheist/src/components/issue_intro_card.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

import '../models/issuedata_model.dart';
import '../util/api/issues_api.dart';
import '../models/issuedata_model.dart';
import '../components/issue_intro_card.dart';

/// The search bar of app for searching issues based on keyword.
class BugHeistSearchDelegate extends SearchDelegate {
Expand Down
Loading

0 comments on commit 0a8fbdb

Please sign in to comment.