Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated outdated packages, made routing global #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
// compileSdkVersion flutter.compileSdkVersion
compileSdkVersion 31
compileSdkVersion 34
ndkVersion flutter.ndkVersion

compileOptions {
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
170 changes: 84 additions & 86 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,87 @@ import 'utils/utils.dart';

void main() => runApp(NetflixApp());

final GlobalKey<NavigatorState> _navigatorState = GlobalKey<NavigatorState>();

final GoRouter router = GoRouter(
initialLocation: '/profile',
navigatorKey: _navigatorState,
routes: [
GoRoute(
path: '/profile',
builder: (BuildContext context, GoRouterState state) {
return const ProfileSelectionScreen();
},
),
ShellRoute(
// observers: [_heroController],
builder: (context, state, child) {
return NetflixScaffold(child: child);
},
routes: <RouteBase>[
GoRoute(
name: 'Home',
path: '/home',
builder: (BuildContext context, GoRouterState state) {
return const HomeScreen();
},
routes: [
GoRoute(
name: 'TV Shows',
path: 'tvshows',
builder: (BuildContext context, GoRouterState state) {
return HomeScreen(name: state.name);
},
pageBuilder: (context, state) {
return CustomTransitionPage<void>(
key: state.pageKey,
child: HomeScreen(name: state.name),
transitionDuration: const Duration(milliseconds: 600),
transitionsBuilder:
(context, animation, secondaryAnimation, child) {
final status = context.read<AnimationStatusCubit>();
animation.removeStatusListener(status.onStatus);
animation.addStatusListener(status.onStatus);
secondaryAnimation
.removeStatusListener(status.onStatus);
secondaryAnimation.addStatusListener(status.onStatus);
return FadeTransition(
opacity: animation, child: child);
});
},
routes: [
GoRoute(
path: 'details',
builder: (BuildContext context, GoRouterState state) {
return MovieDetailsScreen(movie: state.extra as Movie);
},
),
]),
GoRoute(
path: 'details',
builder: (BuildContext context, GoRouterState state) {
return MovieDetailsScreen(movie: state.extra as Movie);
},
),
]),
GoRoute(
path: '/newandhot',
builder: (BuildContext context, GoRouterState state) {
return const NewAndHotScreen();
},
routes: [
GoRoute(
path: 'details',
builder: (BuildContext context, GoRouterState state) {
return MovieDetailsScreen(movie: state.extra as Movie);
},
),
]),
],
),
],
);

class NetflixApp extends StatelessWidget {
NetflixApp({super.key});

Expand All @@ -23,9 +104,9 @@ class NetflixApp extends StatelessWidget {
return BlocWidget(
child: MaterialApp.router(
debugShowCheckedModeBanner: false,
routeInformationProvider: _router.routeInformationProvider,
routeInformationParser: _router.routeInformationParser,
routerDelegate: _router.routerDelegate,
routeInformationProvider: router.routeInformationProvider,
routeInformationParser: router.routeInformationParser,
routerDelegate: router.routerDelegate,
title: 'Netflix',
theme: ThemeData(
brightness: Brightness.dark,
Expand All @@ -41,87 +122,4 @@ class NetflixApp extends StatelessWidget {
),
);
}

final GlobalKey<NavigatorState> _navigatorState = GlobalKey<NavigatorState>();

late final GoRouter _router = GoRouter(
initialLocation: '/profile',
navigatorKey: _navigatorState,
routes: [
GoRoute(
path: '/profile',
builder: (BuildContext context, GoRouterState state) {
return const ProfileSelectionScreen();
},
),
ShellRoute(
// observers: [_heroController],
builder: (context, state, child) {
return NetflixScaffold(child: child);
},
routes: <RouteBase>[
GoRoute(
name: 'Home',
path: '/home',
builder: (BuildContext context, GoRouterState state) {
return const HomeScreen();
},
routes: [
GoRoute(
name: 'TV Shows',
path: 'tvshows',
builder: (BuildContext context, GoRouterState state) {
return HomeScreen(name: state.name);
},
pageBuilder: (context, state) {
return CustomTransitionPage<void>(
key: state.pageKey,
child: HomeScreen(name: state.name),
transitionDuration: const Duration(milliseconds: 600),
transitionsBuilder:
(context, animation, secondaryAnimation, child) {
final status = context.read<AnimationStatusCubit>();
animation.removeStatusListener(status.onStatus);
animation.addStatusListener(status.onStatus);
secondaryAnimation
.removeStatusListener(status.onStatus);
secondaryAnimation
.addStatusListener(status.onStatus);
return FadeTransition(
opacity: animation, child: child);
});
},
routes: [
GoRoute(
path: 'details',
builder: (BuildContext context, GoRouterState state) {
return MovieDetailsScreen(
movie: state.extra as Movie);
},
),
]),
GoRoute(
path: 'details',
builder: (BuildContext context, GoRouterState state) {
return MovieDetailsScreen(movie: state.extra as Movie);
},
),
]),
GoRoute(
path: '/newandhot',
builder: (BuildContext context, GoRouterState state) {
return const NewAndHotScreen();
},
routes: [
GoRoute(
path: 'details',
builder: (BuildContext context, GoRouterState state) {
return MovieDetailsScreen(movie: state.extra as Movie);
},
),
]),
],
),
],
);
}
2 changes: 1 addition & 1 deletion lib/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class _HomeScreenState extends State<HomeScreen> {

@override
void didChangeDependencies() {
if (GoRouterState.of(context).location != '/home/tvshows') {
if (GoRouterState.of(context).fullPath != '/home/tvshows') {
context.read<AnimationStatusCubit>().onStatus(null);
}
super.didChangeDependencies();
Expand Down
6 changes: 3 additions & 3 deletions lib/screens/movie_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ class _MovieDetailsScreenState extends State<MovieDetailsScreen>
],
),
),
Row(
const Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: const [
children: [
NewAndHotTileAction(
icon: LucideIcons.plus,
label: 'My List',
Expand Down Expand Up @@ -358,7 +358,7 @@ class _MovieDetailsScreenState extends State<MovieDetailsScreen>
},
);

Overlay.of(context, rootOverlay: true)?.insert(overlay);
Overlay.of(context, rootOverlay: true).insert(overlay);
}

Widget _seasonDropdown(Movie movie, int seasonNumber) {
Expand Down
10 changes: 5 additions & 5 deletions lib/widgets/netflix_app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class NetflixHeader extends SliverPersistentHeaderDelegate {
status.state != AnimationStatus.reverse ? 1.0 : 0.0;
final canPop = GoRouter.of(context).canPop();

final location = GoRouterState.of(context).location;
final isTvShowsPage = location.contains('tvshows');
final location = GoRouterState.of(context).fullPath;
final isTvShowsPage = location?.contains('tvshows') ?? false;
final opacity = isTvShowsPage
? (status.state == AnimationStatus.completed ? 1.0 : 0.0)
: (status.state == AnimationStatus.forward ? 0.0 : 1.0);
Expand Down Expand Up @@ -227,8 +227,8 @@ class NetflixBottomHeader extends SliverPersistentHeaderDelegate {
return previous != current;
}),
builder: (context, status) {
final location = GoRouterState.of(context).location;
final isTvShowsPage = location.contains('tvshows');
final location = GoRouterState.of(context).fullPath;
final isTvShowsPage = location?.contains('tvshows') ?? false;
final opacity = isTvShowsPage
? (status == AnimationStatus.completed ? 1.0 : 0.0)
: (status == AnimationStatus.forward ? 0.0 : 1.0);
Expand Down Expand Up @@ -385,7 +385,7 @@ class NetflixBottomHeaderTVShows extends SliverPersistentHeaderDelegate {
onPressed: () {
context.go('/tvshows');
},
child: Row(children: const [
child: const Row(children: [
Text('All Categories'),
SizedBox(
width: 8.0,
Expand Down
12 changes: 7 additions & 5 deletions lib/widgets/netflix_bottom_sheet.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_netflix/main.dart';
import 'package:flutter_netflix/repository/repository.dart';
import 'package:go_router/go_router.dart';
import 'package:lucide_icons/lucide_icons.dart';
Expand Down Expand Up @@ -33,8 +34,8 @@ class NetflixBottomSheet extends StatelessWidget {
0.65,
1.0
]),
child: Row(
children: const [
child: const Row(
children: [
Text(
'2022',
style: TextStyle(color: Colors.grey, fontSize: 14.0),
Expand Down Expand Up @@ -189,9 +190,9 @@ class NetflixBottomSheet extends StatelessWidget {
)
],
),
Row(
const Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: const [
children: [
BottomSheetButton(
icon: Icons.play_arrow,
label: 'Play',
Expand All @@ -218,7 +219,8 @@ class NetflixBottomSheet extends StatelessWidget {
InkWell(
onTap: () {
Navigator.pop(context);
context.go('${GoRouter.of(context).location}/details',
context.go(
'${router.routerDelegate.currentConfiguration.fullPath}/details',
extra: movieDetails);
},
child: Row(
Expand Down
4 changes: 3 additions & 1 deletion lib/widgets/new_and_hot_tile.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_netflix/main.dart';
import 'package:flutter_netflix/widgets/genre.dart';
import 'package:go_router/go_router.dart';
import 'package:intl/intl.dart';
Expand All @@ -18,7 +19,8 @@ class NewAndHotTile extends StatelessWidget {
var date = movie.releaseDate ?? DateTime.now();
return InkWell(
onTap: () {
context.go('${GoRouterState.of(context).location}/details',
context.go(
'${router.routerDelegate.currentConfiguration.fullPath}/details',
extra: movie);
},
child: Row(
Expand Down
2 changes: 1 addition & 1 deletion macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import FlutterMacOS
import Foundation

import path_provider_macos
import path_provider_foundation
import sqflite

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
Expand Down
Loading