Skip to content

Commit

Permalink
fixed issue #15 #48 #51 #53
Browse files Browse the repository at this point in the history
  • Loading branch information
justary27 committed Jul 16, 2022
1 parent a199710 commit 7828fbd
Show file tree
Hide file tree
Showing 33 changed files with 1,134 additions and 477 deletions.
5 changes: 5 additions & 0 deletions lib/components/appbar.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:bugheist/components/searchbar.dart';
import 'package:bugheist/routes/routing.dart';
import 'package:flutter/material.dart';

Expand All @@ -14,6 +15,10 @@ AppBar buildAppBar({required BuildContext context}) {
Icons.search,
),
onPressed: () {
showSearch(
context: context,
delegate: BugHeistSearchDelegate(),
);
// do something
},
),
Expand Down
21 changes: 9 additions & 12 deletions lib/components/issue_intro_card.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import 'package:bugheist/data/models.dart';
import 'package:bugheist/routes/routing.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

import '../models/issue_model.dart';

class IssueCard extends StatelessWidget {
final Results result;
final Issue issue;

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

@override
Widget build(BuildContext context) {
Expand All @@ -24,7 +25,7 @@ class IssueCard extends StatelessWidget {
Navigator.pushNamed(
context,
RouteManager.issueDetailPage,
arguments: result,
arguments: issue,
);
},
child: Container(
Expand All @@ -37,7 +38,7 @@ class IssueCard extends StatelessWidget {
child: DecoratedBox(
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(result.screenshot),
image: NetworkImage(issue.screenshotLink),
fit: BoxFit.cover,
),
),
Expand All @@ -52,7 +53,7 @@ class IssueCard extends StatelessWidget {
Container(
padding: const EdgeInsets.only(top: 12),
child: Text(
"Issue #" + result.id,
"Issue #${issue.id}",
overflow: TextOverflow.ellipsis,
softWrap: true,
style: GoogleFonts.ubuntu(
Expand All @@ -67,7 +68,7 @@ class IssueCard extends StatelessWidget {
Container(
padding: const EdgeInsets.only(top: 8, bottom: 12),
child: Text(
result.description.replaceAll("\n", " "),
issue.description.replaceAll("\n", " "),
overflow: TextOverflow.ellipsis,
softWrap: true,
style: GoogleFonts.aBeeZee(
Expand All @@ -83,11 +84,7 @@ class IssueCard extends StatelessWidget {
Container(
padding: const EdgeInsets.only(bottom: 12),
child: Text(
result.createdOn.toLocal().day.toString() +
"/" +
result.createdOn.toLocal().month.toString() +
"/" +
result.createdOn.toLocal().year.toString(),
issue.created_date,
overflow: TextOverflow.ellipsis,
softWrap: true,
style: GoogleFonts.aBeeZee(
Expand Down
27 changes: 27 additions & 0 deletions lib/components/issuechip.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

import '../models/issue_model.dart';

class IssueStatusChip extends StatelessWidget {
final Issue issue;
const IssueStatusChip({
Key? key,
required this.issue,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return Chip(
label: Text(
(issue.isOpen) ? "Open" : "Closed",
style: GoogleFonts.aBeeZee(
textStyle: TextStyle(
fontSize: 10,
color: (issue.isOpen) ? Color(0xFFA3A3A3) : Color(0xFFDC4654),
),
),
),
);
}
}
93 changes: 93 additions & 0 deletions lib/components/searchbar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import 'package:bugheist/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';

class BugHeistSearchDelegate extends SearchDelegate {
@override
List<Widget>? buildActions(BuildContext context) {
return [
IconButton(
onPressed: () {
query = '';
},
icon: Icon(
Icons.clear,
color: Color(0xFFDC4654),
),
),
];
}

@override
Widget? buildLeading(BuildContext context) {
return IconButton(
icon: Icon(
Icons.arrow_back_ios_new_rounded,
color: Color(0xFFDC4654),
),
onPressed: () {
Navigator.of(context).pop();
},
);
}

@override
Widget buildResults(BuildContext context) {
Future _getObj = IssueApiClient.searchIssueByKeyWord(query);

ScrollController _scrollController = new ScrollController();

return FutureBuilder(
future: _getObj,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasError) {
return Center(
child: Text(
'Something went wrong!',
style: TextStyle(fontSize: 18),
),
);
} else if (snapshot.hasData) {
return ListView.builder(
padding: EdgeInsets.symmetric(horizontal: 20),
itemCount: (snapshot.data! as IssueData).issueList!.length,
controller: _scrollController,
itemBuilder: (context, index) {
return IssueCard(
issue: (snapshot.data! as IssueData).issueList![index],
);
},
);
}
}
return Center(
child: CircularProgressIndicator(),
);
},
);
}

@override
Widget buildSuggestions(BuildContext context) {
final Size size = MediaQuery.of(context).size;
return Container(
width: size.width,
height: size.height,
child: Center(
child: Text(
'Search an issue!',
style: GoogleFonts.ubuntu(
textStyle: TextStyle(
color: Color(0xFF737373),
fontSize: 20,
),
),
),
),
);
}
}
52 changes: 0 additions & 52 deletions lib/data/models.dart
Original file line number Diff line number Diff line change
@@ -1,55 +1,3 @@
class DataModel {
final String count;
String next;
final String previous;
final List<Results> results;

DataModel(
{required this.count,
required this.next,
required this.previous,
required this.results});

factory DataModel.fromJson(Map<String, dynamic> parsedJson) {
return DataModel(
count: parsedJson['count'].toString(),
next: parsedJson['next'].toString(),
previous: parsedJson['previous'].toString(),
results: parseResults(parsedJson));
}
static List<Results> parseResults(parsedJson) {
var list = parsedJson['results'] as List;
List<Results> resultsList =
list.map((data) => Results.fromJson(data)).toList();
return resultsList;
}
}

class Results {
final String id;
final String description;
final String screenshot;
final bool isOpen;
final DateTime createdOn;
Results({
required this.id,
required this.description,
required this.screenshot,
required this.isOpen,
required this.createdOn,
});

factory Results.fromJson(Map<String, dynamic> parsedJson) {
return Results(
id: parsedJson['id'].toString(),
description: parsedJson['description'],
screenshot: parsedJson['screenshot'],
isOpen: (parsedJson["status"] == "open") ? true : false,
createdOn: DateTime.parse(parsedJson["created"]),
);
}
}

class Leaders {
final String id;
final int rank;
Expand Down
91 changes: 91 additions & 0 deletions lib/models/issue_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import 'package:intl/intl.dart';

import './user_model.dart';

class Issue {
final int id;
final User? user;
final String url;
final String description;
final String label;
final bool isVerified;
final int? score;
final bool isOpen;
final String userAgent;
final String ocr;
final String screenshotLink;
final DateTime? closedDate;
final String githubUrl;
final DateTime created;
final DateTime? lastModified;
final int? hunt;
final int? domain;
final String? closedBy;

final DateFormat dateFormatter = DateFormat('d MMMM, yyyy');

String? get closed_date {
return (closedDate != null)
? dateFormatter.format(closedDate!.toLocal())
: null;
}

String get created_date => dateFormatter.format(created.toLocal());

String? get last_modified_date {
return (lastModified != null)
? dateFormatter.format(lastModified!.toLocal())
: null;
}

Issue({
required this.id,
this.user,
required this.url,
required this.description,
required this.label,
required this.isVerified,
this.score,
required this.isOpen,
required this.userAgent,
required this.ocr,
required this.screenshotLink,
this.closedDate,
required this.githubUrl,
required this.created,
this.lastModified,
this.hunt,
this.domain,
this.closedBy,
});

factory Issue.fromJson(Map<String, dynamic> responseData) {
return Issue(
id: responseData["id"],
user: (responseData["user"] != null)
? User(
id: responseData["user"]["id"],
username: responseData["user"]["username"],
)
: null,
url: responseData["url"],
description: responseData["description"],
label: responseData["label"].toString(),
isVerified: responseData["verified"],
score: responseData["score"],
isOpen: (responseData["status"] == "open") ? true : false,
userAgent: responseData["user_agent"],
ocr: responseData["ocr"],
screenshotLink: responseData["screenshot"],
closedDate: (responseData["closed_date"].runtimeType != Null)
? DateTime.parse(responseData["closed_date"])
: null,
githubUrl: responseData["github_url"],
created: DateTime.parse(responseData["created"]),
lastModified: DateTime.parse(responseData["modified"]),
hunt: responseData["hunt"],
domain: responseData["domain"],
closedBy: responseData["closed_by"],
);
}
}
25 changes: 25 additions & 0 deletions lib/models/issuedata_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:bugheist/models/issue_model.dart';

class IssueData {
final int count;
String? nextQuery;
String? previousQuery;
List<Issue>? issueList;

IssueData({
required this.count,
this.nextQuery,
this.previousQuery,
this.issueList,
});

factory IssueData.fromJson(Map<String, dynamic> responseData) {
print(responseData["next"]);
return IssueData(
count: responseData["count"],
nextQuery: responseData["next"],
previousQuery: responseData["previous"],
issueList: responseData["results"],
);
}
}
Loading

0 comments on commit 7828fbd

Please sign in to comment.