Skip to content

Commit

Permalink
Merge pull request #162 from letsintegreat/stats-api
Browse files Browse the repository at this point in the history
Implement Stats API
  • Loading branch information
Samuel Rosado committed Feb 1, 2023
2 parents cd7ba58 + 2ef6e75 commit 72831ac
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class OnboardPageModel {
final String imagePath;
final String caption;
final String subhead;
final String description;
String description;

OnboardPageModel(
this.primeColor,
Expand Down
9 changes: 9 additions & 0 deletions lib/src/components/onboarding/onboarding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import 'data/onboard_page_data.dart';
import 'models/onboard_page_model.dart';

class Onboarding extends StatefulWidget {
final Map<String, String> stats;

const Onboarding({Key? key, required this.stats}) : super(key: key);
@override
State<Onboarding> createState() => _OnboardingState();
}
Expand All @@ -14,6 +17,12 @@ class _OnboardingState extends State<Onboarding> {
final PageController pageController = PageController();
late OnboardPageModel pageModel;

@override
void initState() {
super.initState();
onboardData[2].description = '${widget.stats["bugs"]} Bugs\n${widget.stats["users"]} Users\n${widget.stats["hunts"]} Hunts\n${widget.stats["domains"]} Domains';
}

@override
Widget build(BuildContext context) {
return GestureDetector(
Expand Down
4 changes: 2 additions & 2 deletions lib/src/pages/drawer/legal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class LegalPage extends StatelessWidget {
styleSheet: MarkdownStyleSheet.fromTheme(
ThemeData(
textTheme: TextTheme(
bodyText2: GoogleFonts.aBeeZee(
bodyMedium: GoogleFonts.aBeeZee(
textStyle: TextStyle(
fontSize: 12,
color: Color(0xFF737373),
Expand Down Expand Up @@ -120,7 +120,7 @@ class LegalPage extends StatelessWidget {
styleSheet: MarkdownStyleSheet.fromTheme(
ThemeData(
textTheme: TextTheme(
bodyText2: GoogleFonts.aBeeZee(
bodyMedium: GoogleFonts.aBeeZee(
textStyle: TextStyle(
fontSize: 12,
color: Color(0xFF737373),
Expand Down
21 changes: 18 additions & 3 deletions lib/src/pages/onboarding_main_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,40 @@ import '../components/onboarding/onboarding.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:bugheist/src/providers/authstate_provider.dart';

import '../util/api/general_api.dart';

class OnboardingMainPage extends ConsumerStatefulWidget {
@override
ConsumerState<OnboardingMainPage> createState() => _OnboardingMainPageState();
}

class _OnboardingMainPageState extends ConsumerState<OnboardingMainPage> {
Map<String, String> stats = {};

@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) async {
await ref.read(authStateNotifier.notifier).loadUserIfRemembered(context);
Map<String, String> new_stats = await GeneralApiClient.getStats();
setState(() {
stats = new_stats;
});
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: Onboarding(),
);
if (stats["bugs"] != null) {
return Scaffold(
body: Onboarding(
stats: stats,
),
);
} else {
return Scaffold(
body: Center(child: CircularProgressIndicator()),
);
}
}
}
30 changes: 30 additions & 0 deletions lib/src/util/api/general_api.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'dart:convert';

import 'package:bugheist/src/util/endpoints/general_endpoints.dart';
import 'package:http/http.dart' as http;

/// Class for accessing the general client.
class GeneralApiClient {
GeneralApiClient._();

/// Get general stats.
static Future<Map<String, String>> getStats() async {
http.Response? response;
Map<String, String> m = {};
try {
response = await http.get(
Uri.parse(GeneralEndPoints.stats),
);
if (response.statusCode == 200) {
var decodedResponse = jsonDecode(response.body);
m["bugs"] = '${decodedResponse["bugs"]}';
m["users"] = '${decodedResponse["users"]}';
m["hunts"] = '${decodedResponse["hunts"]}';
m["domains"] = '${decodedResponse["domains"]}';
}
} catch (e) {
print(e);
}
return m;
}
}
8 changes: 8 additions & 0 deletions lib/src/util/endpoints/general_endpoints.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// Class to access the General endpoints.
class GeneralEndPoints {
GeneralEndPoints._();

static const String baseUrl = "https://www.bugheist.com/";

static const String stats = baseUrl + "api/v1/stats/";
}

0 comments on commit 72831ac

Please sign in to comment.