Skip to content

Commit

Permalink
Add banned apps page
Browse files Browse the repository at this point in the history
Related to #343

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/OWASP-BLT/BLT-Flutter/issues/343?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
DonnieBLT committed Oct 16, 2024
1 parent 6e1f072 commit 467ae89
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//import 'dart:async';

import 'package:blt/src/pages/onboarding_main_page.dart';
import 'package:blt/src/providers/dark_mode_provider.dart';
import 'package:blt/src/providers/language_provider.dart';
Expand All @@ -9,9 +7,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
//import 'package:receive_sharing_intent/receive_sharing_intent.dart';
import 'package:blt/src/pages/banned_apps_page.dart';

/// ### The BLT app's root widget
class BLT extends StatefulWidget {
const BLT({Key? key}) : super(key: key);

Expand Down Expand Up @@ -55,6 +52,9 @@ class BLTState extends State<BLT> {
themeMode:
themeMode.isDarkMode ? ThemeMode.dark : ThemeMode.light,
home: Scaffold(body: OnboardingMainPage()),
routes: {
'/bannedApps': (context) => BannedAppsPage(),
},
);
},
),
Expand Down
81 changes: 81 additions & 0 deletions lib/src/pages/banned_apps_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';

class BannedAppsPage extends StatefulWidget {
@override
_BannedAppsPageState createState() => _BannedAppsPageState();
}

class _BannedAppsPageState extends State<BannedAppsPage> {
String? selectedCountry;
List<String> countries = [];
List<String> bannedApps = [];

@override
void initState() {
super.initState();
fetchCountries();
}

Future<void> fetchCountries() async {
final response = await http.get(Uri.parse('https://example.com/api/countries'));
if (response.statusCode == 200) {
setState(() {
countries = List<String>.from(json.decode(response.body));
});
} else {
throw Exception('Failed to load countries');
}
}

Future<void> fetchBannedApps(String country) async {
final response = await http.get(Uri.parse('https://example.com/api/banned_apps?country=$country'));
if (response.statusCode == 200) {
setState(() {
bannedApps = List<String>.from(json.decode(response.body));
});
} else {
throw Exception('Failed to load banned apps');
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Banned Apps'),
),
body: Column(
children: [
DropdownButton<String>(
hint: Text('Select a country'),
value: selectedCountry,
onChanged: (String? newValue) {
setState(() {
selectedCountry = newValue;
fetchBannedApps(newValue!);
});
},
items: countries.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
Expanded(
child: ListView.builder(
itemCount: bannedApps.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(bannedApps[index]),
);
},
),
),
],
),
);
}
}
9 changes: 9 additions & 0 deletions lib/src/pages/home/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,15 @@ class _HomeState extends ConsumerState<Home> {
);
},
),
ListTile(
title: Text("Banned Apps"),
onTap: () {
Navigator.pushNamed(
context,
'/bannedApps',
);
},
),
SwitchListTile(
title: Text("Dark Mode"),
value: isDarkMode.isDarkMode,
Expand Down

0 comments on commit 467ae89

Please sign in to comment.