Skip to content

Commit

Permalink
fix: navigation back from detail
Browse files Browse the repository at this point in the history
  • Loading branch information
ad-on-is committed Jan 8, 2025
1 parent 0ce8f56 commit 1fdf5c9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 4 additions & 1 deletion lib/ui/pages/home.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:odin/controllers/app_controller.dart';
import 'package:odin/controllers/home_controller.dart';
import 'package:odin/data/models/item_model.dart';
import 'package:odin/helpers.dart';
import 'package:odin/ui/focusnodes.dart';
import 'package:odin/ui/widgets/carousel.dart';
import 'package:odin/ui/widgets/section.dart';

class HomePage extends HookConsumerWidget {
class HomePage extends HookConsumerWidget with BaseHelper {
const HomePage({Key? key}) : super(key: key);

toggleMenuFocus(bool focus) {
Expand Down Expand Up @@ -54,6 +56,7 @@ class HomePage extends HookConsumerWidget {
// return;
// }
ref.read(currentRow.notifier).state = sections[index].url;

// ref.read(selectedSectionProvider.notifier).state =
// sections[index].title;
//
Expand Down
5 changes: 2 additions & 3 deletions lib/ui/widgets/carousel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:odin/helpers.dart';

final childStreamController = StreamController<String>.broadcast();
final currentRow = StateProvider<String>((ref) => "");
final currentRowBeforeDetail = StateProvider<String>((ref) => "");

class OdinCarousel extends HookConsumerWidget with BaseHelper {
const OdinCarousel(
Expand Down Expand Up @@ -128,7 +129,6 @@ class Carousel extends HookConsumerWidget with BaseHelper {
final didx = useDebounced(idx.value, const Duration(milliseconds: 50));
final isAnim = useState(false);
if (isChild) {
logInfo(id);
useMemoized(() {
childStreamController.stream.listen((data) {
if (!data.startsWith(id)) {
Expand All @@ -152,7 +152,6 @@ class Carousel extends HookConsumerWidget with BaseHelper {
}

if (dir == "select") {
logInfo("SELECT ${idx.value}");
if (onEnter != null) {
onEnter!(idx.value);
}
Expand Down Expand Up @@ -218,7 +217,7 @@ class Carousel extends HookConsumerWidget with BaseHelper {
}
}

class Listener extends HookConsumerWidget {
class Listener extends HookConsumerWidget with BaseHelper {
const Listener(
{required this.onIndexChanged,
this.center,
Expand Down
13 changes: 11 additions & 2 deletions lib/ui/widgets/section.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,22 @@ class Section extends HookConsumerWidget with BaseHelper {
}
});
},
onEnter: (idx) {
Navigator.of(context).push(MaterialPageRoute(
onEnter: (idx) async {
Future.delayed(const Duration(milliseconds: 50), () {
ref.read(currentRowBeforeDetail.notifier).state =
ref.read(currentRow);
});
await Navigator.of(context).push(MaterialPageRoute(
builder: (context) => Detail(
item: items[idx].type == "episode"
? items[idx].show!
: items[idx]),
));

Future.delayed(const Duration(milliseconds: 50), () {
ref.read(currentRow.notifier).state =
ref.read(currentRowBeforeDetail);
});
},
keys: const [
PhysicalKeyboardKey.arrowLeft,
Expand Down

0 comments on commit 1fdf5c9

Please sign in to comment.