0

I am using this code to open a new page in flutter:

openPage(BuildContext context, Item item) {
    Navigator.push(
      context,
      MaterialPageRoute(builder: (context) => StoryPage(item: item)),
    );
  }

this is the full code:

import 'package:animations/animations.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_icons/flutter_icons.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:Cruise/src/component/compact_tile.dart';
import 'package:Cruise/src/component/item_card.dart';
import 'package:Cruise/src/component/item_tile.dart';
import 'package:Cruise/src/component/loading_item.dart';
import 'package:Cruise/src/common/helpers.dart';
import 'package:Cruise/src/models/Item.dart';
import 'package:Cruise/src/page/stories_page.dart';
import 'package:Cruise/src/page/story_page.dart';
import 'package:Cruise/src/common/view_manager.dart';

class StoryList extends HookWidget {
  const StoryList({
    Key key,
    @required this.ids,
    @required this.storiesType,
  }) : super(key: key);

  final List<int> ids;

  final StoriesType storiesType;

  _getViewType(ViewType type, Item item) {
    switch (type) {
      case ViewType.compactTile:
        return CompactTile(item: item);
        break;
      case ViewType.itemCard:
        return ItemCard(item: item);
        break;
      case ViewType.itemTile:
        return ItemTile(item: item);
        break;
      default:
        return ItemCard(item: item);
        break;
    }
  }

  openPage(BuildContext context, Item item) {
    Navigator.push(
      context,
      MaterialPageRoute(builder: (context) => StoryPage(item: item)),
    );
  }

  @override
  Widget build(BuildContext context) {
    final currentView = useProvider(viewProvider.state);
    var counter = useState<StoriesType>(storiesType);

    return SliverList(
      delegate: SliverChildBuilderDelegate(
        (context, index) {
          return Consumer(
            (context, read) {
              return read(storyProvider(ids[index])).when(
                loading: () => LoadingItem(count: 1),
                error: (err, trace) => Text("Error: $err"),
                data: (item) {
                  return Slidable(
                    key: Key(item.id.toString()),
                    closeOnScroll: true,
                    actionPane: SlidableScrollActionPane(),
                    actions: <Widget>[
                      IconSlideAction(
                        color: Colors.deepOrangeAccent,
                        icon: Feather.arrow_up_circle,
                        onTap: () => handleUpvote(context, item: item),
                      ),
                    ],
                    dismissal: SlidableDismissal(
                      closeOnCanceled: true,
                      dismissThresholds: {
                        SlideActionType.primary: 0.2,
                        SlideActionType.secondary: 0.2,
                      },
                      child: SlidableDrawerDismissal(),
                      onWillDismiss: (actionType) {
                        handleUpvote(context, item: item);
                        return false;
                      },
                    ),
                    child: Padding(
                      padding: const EdgeInsets.symmetric(horizontal: 16.0),
                      child: OpenContainer(
                        tappable: true,
                        closedElevation: 0,
                        closedColor: Theme.of(context).scaffoldBackgroundColor,
                        openColor: Theme.of(context).scaffoldBackgroundColor,
                        transitionDuration: Duration(milliseconds: 500),
                        closedBuilder: (BuildContext c, VoidCallback action) =>
                            _getViewType(currentView, item),
                        openBuilder: (BuildContext c, VoidCallback action) =>
                            openPage(context, item),
                      ),
                    ),
                  );
                },
              );
            },
          );
        },
        childCount: ids.length,
      ),
    );
  }
}

but when tap iphone left screen and back to the new opened page, not the list page, I want to open a new page and when slip from left to right the opened page closed and back to list page. Am I missing something in this code? Am I doing the right way? I am using in other places works fine but in this code do not work, what should I do to fix it?

I think maybe the OpenContainer animation did not support back in IOS by slide left screen gesture, so I must click the back arrow in AppBar, now I want to slide left screen to back to list page, click button to back is ugly.

Dolphin
  • 29,069
  • 61
  • 260
  • 539
  • Does this answer your question? [Flutter navigation, reopen page instead of pushing it again](https://stackoverflow.com/questions/59457306/flutter-navigation-reopen-page-instead-of-pushing-it-again) – The Chinky Sight Nov 11 '20 at 12:02
  • I tried it seems not work, I think maybe the `OpenContainer` animation did not support back in IOS, so I must click the back arrow in AppBar, now I want to slide left screen to back to list page, click button to back is ugly. @ChinkySight – Dolphin Nov 11 '20 at 14:09

0 Answers0