-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: add bestiari list to pf2e settings model * chore: add bestiary source as a Pf2eBestiaryService dependency * feat: add dialog to select the pf2e bestiary sources * ci: update env variables in CI workflows * style: format
- Loading branch information
1 parent
55eba6f
commit 7a3fbf9
Showing
13 changed files
with
260 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
extension CapitalizeString on String? { | ||
String capitalize() { | ||
if (this == null) return ''; | ||
return '${this![0].toUpperCase()}${this!.substring(1)}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:dio/dio.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
enum Pf2eBestiarySourceStatus { | ||
loading, | ||
loaded, | ||
error, | ||
} | ||
|
||
class Pf2eBestiarySource extends ChangeNotifier { | ||
Pf2eBestiarySourceStatus _status = Pf2eBestiarySourceStatus.loading; | ||
Set<String> _bestiaries = {}; | ||
|
||
Pf2eBestiarySource() { | ||
load(); | ||
} | ||
|
||
Pf2eBestiarySourceStatus get status => _status; | ||
|
||
Set<String> get bestiaries => _bestiaries; | ||
|
||
Future<void> load() async { | ||
_status = Pf2eBestiarySourceStatus.loading; | ||
notifyListeners(); | ||
final dio = | ||
Dio(BaseOptions(baseUrl: const String.fromEnvironment('PF2E_URI'))); | ||
final response = await dio.get('/bestiaries/index.json'); | ||
final sources = | ||
(jsonDecode(response.data) as Map).keys.cast<String>().toSet(); | ||
_bestiaries = sources; | ||
_status = Pf2eBestiarySourceStatus.loaded; | ||
notifyListeners(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import 'package:battlemaster/extensions/string_extension.dart'; | ||
import 'package:battlemaster/features/settings/providers/pf2e_bestiary_source.dart'; | ||
import 'package:battlemaster/features/settings/providers/system_settings_provider.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
class Pf2eBestiaryDialog extends StatelessWidget { | ||
const Pf2eBestiaryDialog({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ChangeNotifierProvider<Pf2eBestiarySource>( | ||
create: (_) => Pf2eBestiarySource(), | ||
child: const _Dialog(), | ||
); | ||
} | ||
} | ||
|
||
class _Dialog extends StatefulWidget { | ||
const _Dialog(); | ||
|
||
@override | ||
State<_Dialog> createState() => _DialogState(); | ||
} | ||
|
||
class _DialogState extends State<_Dialog> { | ||
final _selected = <String>{}; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
final selectedBestiaries = | ||
context.read<SystemSettingsProvider>().pf2eSettings.bestiaries; | ||
_selected.addAll(selectedBestiaries); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final localization = AppLocalizations.of(context)!; | ||
final state = context.watch<Pf2eBestiarySource>(); | ||
return AlertDialog( | ||
title: Text(localization.select_bestiaries_title), | ||
content: SizedBox( | ||
width: 500, | ||
child: state.status == Pf2eBestiarySourceStatus.loading | ||
? const Center(child: CircularProgressIndicator()) | ||
: SingleChildScrollView( | ||
child: Column( | ||
children: [ | ||
for (final bestiary in state.bestiaries.toList()..sort()) | ||
CheckboxListTile( | ||
value: _selected.contains(bestiary), | ||
onChanged: (value) { | ||
setState(() { | ||
if (value!) { | ||
_selected.add(bestiary); | ||
} else { | ||
_selected.remove(bestiary); | ||
} | ||
}); | ||
}, | ||
title: Text( | ||
bestiary | ||
.split('-') | ||
.map((s) => s.capitalize()) | ||
.join(' '), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
actions: [ | ||
OutlinedButton( | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
}, | ||
child: Text(localization.cancel_button), | ||
), | ||
ElevatedButton( | ||
onPressed: () { | ||
Navigator.of(context).pop(_selected); | ||
}, | ||
child: Text(localization.save_button), | ||
), | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.