Skip to content

Commit

Permalink
Moved the game codes section to the homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Mar 9, 2021
1 parent 0b71b67 commit ac5e280
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 22 deletions.
2 changes: 2 additions & 0 deletions lib/main.dart
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_user_agent/flutter_user_agent.dart';
import 'package:genshindb/domain/services/locale_service.dart';
import 'package:genshindb/domain/services/telemetry_service.dart';

Expand All @@ -14,6 +15,7 @@ import 'presentation/app_widget.dart';
Future<void> main() async {
//This is required by app center
WidgetsFlutterBinding.ensureInitialized();
await FlutterUserAgent.init();
await initInjection();
runApp(MyApp());
}
Expand Down
17 changes: 16 additions & 1 deletion lib/presentation/game_codes/game_codes_page.dart
Expand Up @@ -10,6 +10,7 @@ import 'package:genshindb/presentation/shared/loading.dart';
import 'package:genshindb/presentation/shared/styles.dart';
import 'package:genshindb/presentation/shared/utils/toast_utils.dart';
import 'package:genshindb/presentation/shared/wrapped_ascension_material.dart';
import 'package:url_launcher/url_launcher.dart';

class GameCodesPage extends StatelessWidget {
const GameCodesPage({
Expand All @@ -20,7 +21,15 @@ class GameCodesPage extends StatelessWidget {
Widget build(BuildContext context) {
final s = S.of(context);
return Scaffold(
appBar: AppBar(title: Text(s.gameCodes)),
appBar: AppBar(
title: Text(s.gameCodes),
actions: [
IconButton(
icon: const Icon(Icons.open_in_new),
onPressed: () => _launchUrl('https://genshin.mihoyo.com/en/gift'),
)
],
),
body: SafeArea(
child: SingleChildScrollView(
child: Padding(
Expand Down Expand Up @@ -107,4 +116,10 @@ class GameCodesPage extends StatelessWidget {
],
);
}

Future<void> _launchUrl(String url) async {
if (await canLaunch(url)) {
await launch(url);
}
}
}
3 changes: 3 additions & 0 deletions lib/presentation/home/home_page.dart
Expand Up @@ -8,6 +8,7 @@ import 'package:genshindb/presentation/today_materials/materials_page.dart';
import 'widgets/sliver_calculators_card.dart';
import 'widgets/sliver_characters_birthday_card.dart';
import 'widgets/sliver_elements_card.dart';
import 'widgets/sliver_game_codes_card.dart';
import 'widgets/sliver_main_title.dart';
import 'widgets/sliver_settings_card.dart';
import 'widgets/sliver_today_char_ascension_materials.dart';
Expand Down Expand Up @@ -44,6 +45,8 @@ class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin<
SliverWishSimulatorCard(),
SliverMainTitle(title: s.tierListBuilder),
SliverTierList(),
SliverMainTitle(title: s.gameCodes),
SliverGameCodesCard(),
SliverMainTitle(title: s.settings),
SliverSettingsCard(),
],
Expand Down
27 changes: 27 additions & 0 deletions lib/presentation/home/widgets/sliver_game_codes_card.dart
@@ -0,0 +1,27 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:genshindb/application/bloc.dart';
import 'package:genshindb/generated/l10n.dart';
import 'package:genshindb/presentation/game_codes/game_codes_page.dart';

import 'sliver_card_item.dart';

class SliverGameCodesCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final s = S.of(context);
return SliverCardItem(
onClick: _showGameCodesDialog,
icon: Icon(Icons.code, size: 60, color: theme.accentColor),
children: [
Text(s.seeAllInGameGameCodes, textAlign: TextAlign.center, style: theme.textTheme.subtitle2),
],
);
}

Future<void> _showGameCodesDialog(BuildContext context) async {
context.read<GameCodesBloc>().add(const GameCodesEvent.opened());
await Navigator.push(context, MaterialPageRoute(fullscreenDialog: true, builder: (ctx) => const GameCodesPage()));
}
}
1 change: 1 addition & 0 deletions lib/presentation/home/widgets/sliver_settings_card.dart
Expand Up @@ -11,6 +11,7 @@ class SliverSettingsCard extends StatelessWidget {
final s = S.of(context);
return SliverCardItem(
onClick: _gotoSettingsPage,
iconToTheLeft: true,
icon: Icon(Icons.settings, size: 60, color: theme.accentColor),
children: [
Text(s.theme, style: theme.textTheme.subtitle2),
Expand Down
21 changes: 0 additions & 21 deletions lib/presentation/settings/widgets/other_settings.dart
Expand Up @@ -4,7 +4,6 @@ import 'package:genshindb/application/bloc.dart';
import 'package:genshindb/application/settings/settings_bloc.dart';
import 'package:genshindb/domain/enums/enums.dart';
import 'package:genshindb/generated/l10n.dart';
import 'package:genshindb/presentation/game_codes/game_codes_page.dart';
import 'package:genshindb/presentation/shared/extensions/i18n_extensions.dart';
import 'package:genshindb/presentation/shared/loading.dart';
import 'package:genshindb/presentation/shared/styles.dart';
Expand Down Expand Up @@ -89,28 +88,8 @@ class OtherSettings extends StatelessWidget {
);
},
),
ListTile(
dense: false,
title: Text(s.gameCodes),
subtitle: Container(
margin: const EdgeInsets.only(left: 10),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
s.seeAllInGameGameCodes,
style: const TextStyle(color: Colors.grey, fontSize: 11),
),
),
),
onTap: () => _showGameCodesDialog(context),
)
],
),
);
}

Future<void> _showGameCodesDialog(BuildContext context) async {
context.read<GameCodesBloc>().add(const GameCodesEvent.opened());
await Navigator.push(context, MaterialPageRoute(fullscreenDialog: true, builder: (ctx) => const GameCodesPage()));
}
}

0 comments on commit ac5e280

Please sign in to comment.