Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions lib/bottom_nav.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:open_tv/models/view_type.dart';
import 'package:open_tv/settings_view.dart';
Expand All @@ -6,11 +7,17 @@ class BottomNav extends StatefulWidget {
final Function(ViewType) updateViewMode;
final ViewType startingView;
final bool blockSettings;
final bool useRail;
final bool showSearch;
final VoidCallback? onSearch;
const BottomNav({
super.key,
required this.updateViewMode,
this.startingView = ViewType.all,
this.blockSettings = false,
this.useRail = false,
this.showSearch = false,
this.onSearch,
});

@override
Expand Down Expand Up @@ -56,6 +63,57 @@ class _BottomNavState extends State<BottomNav> {

@override
Widget build(BuildContext context) {
if (widget.useRail) {
final includeSearch = widget.showSearch && widget.onSearch != null;
final selectedIndex =
includeSearch ? _selectedIndex + 1 : _selectedIndex;
return Container(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceBright,
border: Border(
right: BorderSide(
color: Theme.of(context).colorScheme.surfaceBright,
width: 1))),
child: NavigationRail(
selectedIndex: selectedIndex,
onDestinationSelected: (index) {
if (includeSearch && index == 0) {
widget.onSearch!();
return;
}
final adjustedIndex = includeSearch ? index - 1 : index;
onBarTapped(adjustedIndex);
},
labelType: NavigationRailLabelType.all,
destinations: <NavigationRailDestination>[
if (includeSearch)
const NavigationRailDestination(
icon: Icon(Icons.search),
label: Text('Search'),
),
const NavigationRailDestination(
icon: Icon(Icons.list),
label: Text('All'),
),
const NavigationRailDestination(
icon: Icon(Icons.dashboard),
label: Text('Categories'),
),
const NavigationRailDestination(
icon: Icon(Icons.star),
label: Text('Favorites'),
),
const NavigationRailDestination(
icon: Icon(Icons.history),
label: Text('History'),
),
const NavigationRailDestination(
icon: Icon(Icons.settings),
label: Text('Settings'),
),
],
));
}
return Container(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceBright,
Expand Down Expand Up @@ -91,3 +149,15 @@ class _BottomNavState extends State<BottomNav> {
));
}
}

bool shouldUseSideNav(BuildContext context) {
final media = MediaQuery.of(context);
final navigationMode =
MediaQuery.maybeNavigationModeOf(context) ?? NavigationMode.traditional;
final isLargeLandscape =
media.size.width >= 900 && media.size.width > media.size.height;
final isAndroidLike =
!kIsWeb && defaultTargetPlatform == TargetPlatform.android;
return isLargeLandscape &&
(navigationMode == NavigationMode.directional || isAndroidLike);
}
204 changes: 111 additions & 93 deletions lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,87 @@ class _HomeState extends State<Home> {

@override
Widget build(BuildContext context) {
final useSideNav = shouldUseSideNav(context);
final content = Column(children: [
AnimatedSize(
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
child: searchMode
? Container(
padding:
const EdgeInsets.symmetric(horizontal: 10, vertical: 8),
color: Theme.of(context)
.colorScheme
.surfaceContainer, // Background color
child: Row(
children: [
Expanded(
child: TextField(
controller: searchController,
focusNode: _focusNode,
onChanged: (query) {
_debounce?.cancel();
_debounce =
Timer(const Duration(milliseconds: 500), () {
widget.home.filters.query = query;
load(false);
});
},
decoration: InputDecoration(
hintText: "Search...",
prefixIcon: const Icon(Icons.search),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide.none,
),
suffixIcon: IconButton(
onPressed: () {
widget.home.filters.useKeywords =
!widget.home.filters.useKeywords;
load(false);
},
icon: Icon(widget.home.filters.useKeywords
? Icons.label
: Icons.label_outline)),
filled: true, // Light background for contrast
contentPadding:
const EdgeInsets.symmetric(vertical: 0),
),
)),
const SizedBox(width: 10),
SizedBox(
width: 40,
child: IconButton(
onPressed: toggleSearch,
icon: const Icon(
Icons.close,
)))
],
),
)
: const SizedBox.shrink()),
Expanded(
child: GridView.builder(
shrinkWrap: true,
controller: _scrollController,
padding: const EdgeInsets.fromLTRB(16, 15, 16, 5),
itemCount: channels.length,
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 315,
mainAxisExtent: 120,
mainAxisSpacing: 16,
crossAxisSpacing: 16,
),
itemBuilder: (context, index) {
final channel = channels[index];
return ChannelTile(
channel: channel,
parentContext: context,
setNode: setNode,
);
},
)),
]);
return PopScope(
canPop: canPop(),
onPopInvokedWithResult: (didPop, result) {
Expand All @@ -211,98 +292,35 @@ class _HomeState extends State<Home> {
: null,
body: Loading(
child: SafeArea(
child: Column(children: [
AnimatedSize(
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
child: searchMode
? Container(
padding: const EdgeInsets.symmetric(
horizontal: 10, vertical: 8),
color: Theme.of(context)
.colorScheme
.surfaceContainer, // Background color
child: Row(
children: [
Expanded(
child: TextField(
controller: searchController,
focusNode: _focusNode,
onChanged: (query) {
_debounce?.cancel();
_debounce = Timer(
const Duration(milliseconds: 500), () {
widget.home.filters.query = query;
load(false);
});
},
decoration: InputDecoration(
hintText: "Search...",
prefixIcon: const Icon(Icons.search),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide.none,
),
suffixIcon: IconButton(
onPressed: () {
widget.home.filters.useKeywords =
!widget.home.filters.useKeywords;
load(false);
},
icon: Icon(widget.home.filters.useKeywords
? Icons.label
: Icons.label_outline)),
filled: true, // Light background for contrast
contentPadding:
const EdgeInsets.symmetric(vertical: 0),
),
)),
const SizedBox(width: 10),
SizedBox(
width: 40,
child: IconButton(
onPressed: toggleSearch,
icon: const Icon(
Icons.close,
)))
],
),
)
: const SizedBox.shrink()),
Expanded(
child: GridView.builder(
shrinkWrap: true,
controller: _scrollController,
padding: const EdgeInsets.fromLTRB(16, 15, 16, 5),
itemCount: channels.length,
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 315,
mainAxisExtent: 120,
mainAxisSpacing: 16,
crossAxisSpacing: 16,
),
itemBuilder: (context, index) {
final channel = channels[index];
return ChannelTile(
channel: channel,
parentContext: context,
setNode: setNode,
);
},
)),
]))),
bottomNavigationBar: BottomNav(
startingView: getStartingView(),
blockSettings: blockSettings,
updateViewMode: updateViewMode,
),
floatingActionButton: Visibility(
visible: !searchMode,
child: FloatingActionButton(
onPressed: toggleSearch,
tooltip: 'Search',
child: const Icon(Icons.search),
),
)));
child: useSideNav
? Row(children: [
BottomNav(
startingView: getStartingView(),
blockSettings: blockSettings,
updateViewMode: updateViewMode,
useRail: true,
showSearch: true,
onSearch: toggleSearch,
),
Expanded(child: content),
])
: content)),
bottomNavigationBar: useSideNav
? null
: BottomNav(
startingView: getStartingView(),
blockSettings: blockSettings,
updateViewMode: updateViewMode,
),
floatingActionButton: useSideNav
? null
: Visibility(
visible: !searchMode,
child: FloatingActionButton(
onPressed: toggleSearch,
tooltip: 'Search',
child: const Icon(Icons.search),
),
)));
}
}
Loading