-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Presentation] Added a custom scaffold for mobile and desktop / tablet
- Loading branch information
Showing
27 changed files
with
772 additions
and
459 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
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/artifacts/artifacts_page.dart'; | ||
import 'package:genshindb/presentation/characters/characters_page.dart'; | ||
import 'package:genshindb/presentation/home/home_page.dart'; | ||
import 'package:genshindb/presentation/map/map_page.dart'; | ||
import 'package:genshindb/presentation/settings/settings_page.dart'; | ||
import 'package:genshindb/presentation/shared/extensions/focus_scope_node_extensions.dart'; | ||
import 'package:genshindb/presentation/shared/genshin_db_icons.dart'; | ||
import 'package:genshindb/presentation/weapons/weapons_page.dart'; | ||
|
||
typedef OnWillPop = Future<bool> Function(); | ||
|
||
class DesktopTabletScaffold extends StatefulWidget { | ||
final int defaultIndex; | ||
final TabController tabController; | ||
|
||
const DesktopTabletScaffold({ | ||
Key? key, | ||
required this.defaultIndex, | ||
required this.tabController, | ||
}) : super(key: key); | ||
|
||
@override | ||
_DesktopTabletScaffoldState createState() => _DesktopTabletScaffoldState(); | ||
} | ||
|
||
class _DesktopTabletScaffoldState extends State<DesktopTabletScaffold> { | ||
late int _index; | ||
|
||
@override | ||
void initState() { | ||
_index = widget.defaultIndex; | ||
super.initState(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final s = S.of(context); | ||
final extended = MediaQuery.of(context).orientation != Orientation.portrait; | ||
return Scaffold( | ||
body: SafeArea( | ||
child: BlocListener<MainTabBloc, MainTabState>( | ||
listener: (ctx, state) async { | ||
state.maybeMap( | ||
initial: (s) => _changeCurrentTab(s.currentSelectedTab), | ||
orElse: () => {}, | ||
); | ||
}, | ||
child: Row( | ||
children: <Widget>[ | ||
NavigationRail( | ||
selectedIndex: _index, | ||
onDestinationSelected: (index) => _gotoTab(index), | ||
labelType: extended ? null : NavigationRailLabelType.selected, | ||
extended: extended, | ||
destinations: <NavigationRailDestination>[ | ||
NavigationRailDestination( | ||
icon: const Icon(Icons.people), | ||
selectedIcon: const Icon(Icons.people), | ||
label: Text(s.characters), | ||
), | ||
NavigationRailDestination( | ||
icon: const Icon(GenshinDb.crossed_swords), | ||
selectedIcon: const Icon(GenshinDb.crossed_swords), | ||
label: Text(s.weapons), | ||
), | ||
NavigationRailDestination( | ||
icon: const Icon(Icons.home), | ||
selectedIcon: const Icon(Icons.home), | ||
label: Text(s.home), | ||
), | ||
NavigationRailDestination( | ||
icon: const Icon(GenshinDb.overmind), | ||
selectedIcon: const Icon(GenshinDb.overmind), | ||
label: Text(s.artifacts), | ||
), | ||
NavigationRailDestination( | ||
icon: const Icon(Icons.map), | ||
selectedIcon: const Icon(Icons.map), | ||
label: Text(s.map), | ||
), | ||
NavigationRailDestination( | ||
icon: const Icon(Icons.settings), | ||
selectedIcon: const Icon(Icons.settings), | ||
label: Text(s.settings), | ||
), | ||
], | ||
), | ||
const VerticalDivider(thickness: 1, width: 1), | ||
// This is the main content. | ||
Expanded( | ||
child: TabBarView( | ||
controller: widget.tabController, | ||
physics: const NeverScrollableScrollPhysics(), | ||
children: [ | ||
const CharactersPage(), | ||
const WeaponsPage(), | ||
HomePage(), | ||
const ArtifactsPage(), | ||
MapPage(), | ||
], | ||
), | ||
) | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
|
||
void _changeCurrentTab(int index) { | ||
FocusScope.of(context).removeFocus(); | ||
widget.tabController.index = index; | ||
|
||
setState(() { | ||
_index = index; | ||
}); | ||
} | ||
|
||
Future<void> _gotoTab(int newIndex) async { | ||
if (newIndex == 5) { | ||
await _gotoSettingsPage(); | ||
return; | ||
} | ||
context.read<MainTabBloc>().add(MainTabEvent.goToTab(index: newIndex)); | ||
} | ||
|
||
Future<void> _gotoSettingsPage() async { | ||
final route = MaterialPageRoute(builder: (c) => SettingsPage()); | ||
await Navigator.push(context, route); | ||
} | ||
} |
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
61 changes: 61 additions & 0 deletions
61
lib/presentation/home/widgets/ascension_material_item_card.dart
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,61 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:genshindb/generated/l10n.dart'; | ||
import 'package:genshindb/presentation/shared/extensions/i18n_extensions.dart'; | ||
import 'package:genshindb/presentation/shared/material_item_button.dart'; | ||
import 'package:genshindb/presentation/shared/styles.dart'; | ||
|
||
class AscensionMaterialItemCard extends StatelessWidget { | ||
final String name; | ||
final String image; | ||
final List<int> days; | ||
final Widget child; | ||
|
||
const AscensionMaterialItemCard({ | ||
Key? key, | ||
required this.name, | ||
required this.image, | ||
required this.days, | ||
required this.child, | ||
}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final s = S.of(context); | ||
final theme = Theme.of(context); | ||
final obtainOn = s.translateDays(days); | ||
|
||
return Card( | ||
margin: Styles.edgeInsetAll10, | ||
shape: Styles.cardShape, | ||
child: Container( | ||
width: 250, | ||
padding: Styles.edgeInsetAll5, | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
MaterialItemButton(image: image, size: 100), | ||
Tooltip( | ||
message: name, | ||
child: Text( | ||
name, | ||
textAlign: TextAlign.center, | ||
overflow: TextOverflow.ellipsis, | ||
style: theme.textTheme.subtitle1!.copyWith(fontWeight: FontWeight.bold), | ||
), | ||
), | ||
Tooltip( | ||
message: obtainOn, | ||
child: Text( | ||
obtainOn, | ||
textAlign: TextAlign.center, | ||
overflow: TextOverflow.visible, | ||
style: theme.textTheme.subtitle2!.copyWith(fontSize: 12), | ||
), | ||
), | ||
child, | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.