Skip to content

Commit e24edc9

Browse files
committed
updating router
1 parent 749ce12 commit e24edc9

File tree

7 files changed

+128
-124
lines changed

7 files changed

+128
-124
lines changed

dataconnect/lib/actor_detail.dart

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -14,64 +14,65 @@ class ActorDetail extends StatelessWidget {
1414
@override
1515
Widget build(BuildContext context) {
1616
return FutureBuilder(
17-
future: MovieState.getActorById(actorId),
18-
builder: (context, snapshot) {
19-
final actor = snapshot.data?.data.actor;
20-
final loading = snapshot.connectionState == ConnectionState.waiting;
21-
return Scaffold(
22-
body: SafeArea(
23-
child: () {
24-
if (actor == null || loading) {
25-
return const Center(
26-
child: CircularProgressIndicator(),
27-
);
28-
}
29-
return Padding(
30-
padding: const EdgeInsets.all(30),
31-
child: SingleChildScrollView(
32-
child: Column(
33-
children: [
34-
Align(
35-
alignment: Alignment.centerLeft,
36-
child: Text(
37-
actor.name,
38-
style: const TextStyle(fontSize: 30),
39-
)),
40-
Row(
41-
mainAxisAlignment: MainAxisAlignment.start,
42-
crossAxisAlignment: CrossAxisAlignment.start,
43-
children: [
44-
Expanded(
45-
child: AspectRatio(
46-
aspectRatio:
47-
9 / 16, // 9:16 aspect ratio for the image
48-
child: Image.network(
49-
actor.imageUrl,
50-
fit: BoxFit.cover,
51-
),
17+
future: MovieState.getActorById(actorId),
18+
builder: (context, snapshot) {
19+
final actor = snapshot.data?.data.actor;
20+
final loading = snapshot.connectionState == ConnectionState.waiting;
21+
return Scaffold(
22+
body: SafeArea(
23+
child: () {
24+
if (actor == null || loading) {
25+
return const Center(
26+
child: CircularProgressIndicator(),
27+
);
28+
}
29+
return Padding(
30+
padding: const EdgeInsets.all(30),
31+
child: SingleChildScrollView(
32+
child: Column(
33+
children: [
34+
Align(
35+
alignment: Alignment.centerLeft,
36+
child: Text(
37+
actor.name,
38+
style: const TextStyle(fontSize: 30),
39+
)),
40+
Row(
41+
mainAxisAlignment: MainAxisAlignment.start,
42+
crossAxisAlignment: CrossAxisAlignment.start,
43+
children: [
44+
Expanded(
45+
child: AspectRatio(
46+
aspectRatio:
47+
9 / 16, // 9:16 aspect ratio for the image
48+
child: Image.network(
49+
actor.imageUrl,
50+
fit: BoxFit.cover,
5251
),
5352
),
54-
],
55-
),
56-
ListMovies(
57-
movies: MovieState.convertMainActorDetail(
58-
actor.mainActors,
5953
),
60-
title: "Main Roles",
54+
],
55+
),
56+
ListMovies(
57+
movies: MovieState.convertMainActorDetail(
58+
actor.mainActors,
6159
),
62-
ListMovies(
63-
movies: MovieState.convertSupportingActorDetail(
64-
actor.supportingActors,
65-
),
66-
title: "Supporting Roles",
60+
title: "Main Roles",
61+
),
62+
ListMovies(
63+
movies: MovieState.convertSupportingActorDetail(
64+
actor.supportingActors,
6765
),
68-
],
69-
),
66+
title: "Supporting Roles",
67+
),
68+
],
7069
),
71-
);
72-
}(),
73-
),
74-
);
75-
});
70+
),
71+
);
72+
}(),
73+
),
74+
);
75+
},
76+
);
7677
}
7778
}

dataconnect/lib/destination.dart

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
import 'package:flutter/material.dart';
22

3-
class Route {
3+
class Route extends NavigationDestination {
44
Route({
5+
super.key,
56
required this.path,
6-
required this.label,
7+
required super.label,
78
required this.iconData,
8-
});
9+
}) : super(icon: Icon(iconData));
910
final String path;
10-
final String label;
1111
final IconData iconData;
12-
13-
NavigationDestination toDestination() {
14-
return NavigationDestination(
15-
icon: Icon(iconData),
16-
label: label,
17-
);
18-
}
1912
}
2013

2114
final homePath = Route(

dataconnect/lib/movie_detail.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class _MovieDetailState extends State<MovieDetail> {
176176
],
177177
),
178178
),
179-
Container(
179+
SizedBox(
180180
height: 125,
181181
child: Column(
182182
mainAxisAlignment: MainAxisAlignment.start,

dataconnect/lib/movie_state.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import 'package:dataconnect/movies_connector/movies.dart';
21
import 'package:firebase_data_connect/firebase_data_connect.dart';
32

3+
import 'movies_connector/movies.dart';
44
import 'models/movie.dart';
55

66
class MovieState {

dataconnect/lib/navigation_shell.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ class NavigationShell extends StatelessWidget {
2929
bottomNavigationBar: NavigationBar(
3030
selectedIndex: navigationShell.currentIndex,
3131
onDestinationSelected: _goBranch,
32-
destinations: paths //
33-
.map((destination) => destination.toDestination())
34-
.toList(),
32+
destinations: paths,
3533
),
3634
);
3735
}

dataconnect/lib/router.dart

Lines changed: 62 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,77 @@
1-
import 'package:dataconnect/destination.dart';
2-
import 'package:dataconnect/login.dart';
3-
import 'package:dataconnect/profile.dart';
4-
import 'package:dataconnect/search.dart';
51
import 'package:go_router/go_router.dart';
62

3+
import 'login.dart';
4+
import 'destination.dart';
5+
import 'profile.dart';
6+
import 'search.dart';
77
import 'actor_detail.dart';
88
import 'main.dart';
99
import 'movie_detail.dart';
1010
import 'navigation_shell.dart';
1111
import 'sign_up.dart';
1212
import 'util/auth.dart';
1313

14-
var router = GoRouter(initialLocation: homePath.path, routes: [
15-
StatefulShellRoute.indexedStack(
14+
var router = GoRouter(
15+
refreshListenable: Auth.instance,
16+
initialLocation: homePath.path,
17+
routes: [
18+
StatefulShellRoute.indexedStack(
1619
builder: (context, state, navigationShell) {
1720
return NavigationShell(navigationShell: navigationShell);
1821
},
1922
branches: [
20-
StatefulShellBranch(routes: [
21-
GoRoute(
22-
path: homePath.path,
23-
builder: (context, state) => const MyHomePage(),
24-
),
25-
GoRoute(
26-
path: '/movies/:movieId',
27-
builder: (context, state) =>
28-
MovieDetail(id: state.pathParameters['movieId']!)),
29-
GoRoute(
30-
path: "/actors",
31-
redirect: (context, state) =>
32-
'/actors/${state.pathParameters['actorId']}',
33-
routes: [
34-
GoRoute(
35-
path: ":actorId",
36-
builder: (context, state) =>
37-
ActorDetail(actorId: state.pathParameters['actorId']!))
38-
])
39-
]),
40-
StatefulShellBranch(routes: [
41-
GoRoute(
42-
path: "/search",
43-
builder: (context, state) => const Search(),
44-
),
45-
]),
46-
StatefulShellBranch(routes: [
47-
GoRoute(
48-
path: "/profile",
23+
StatefulShellBranch(
24+
routes: [
25+
GoRoute(
26+
path: homePath.path,
27+
builder: (context, state) => const MyHomePage(),
28+
),
29+
GoRoute(
30+
path: '/movies/:movieId',
31+
builder: (context, state) =>
32+
MovieDetail(id: state.pathParameters['movieId']!)),
33+
GoRoute(
34+
path: "/actors",
35+
redirect: (context, state) =>
36+
'/actors/${state.pathParameters['actorId']}',
37+
routes: [
38+
GoRoute(
39+
path: ":actorId",
40+
builder: (context, state) => ActorDetail(
41+
actorId: state.pathParameters['actorId']!))
42+
])
43+
],
44+
),
45+
StatefulShellBranch(
46+
routes: [
47+
GoRoute(
48+
path: "/search",
49+
builder: (context, state) => const Search(),
50+
),
51+
],
52+
),
53+
StatefulShellBranch(
54+
routes: [
55+
GoRoute(
56+
path: "/profile",
57+
redirect: (context, state) async {
58+
return Auth.instance.isLoggedIn ? null : '/login';
59+
},
60+
builder: (context, state) => const Profile()),
61+
GoRoute(
62+
path: "/login",
63+
builder: (context, state) => const Login(),
4964
redirect: (context, state) async {
50-
return Auth.instance.isLoggedIn ? null : '/login';
65+
return Auth.instance.isLoggedIn ? '/profile' : null;
5166
},
52-
builder: (context, state) => const Profile()),
53-
GoRoute(
54-
path: "/login",
55-
builder: (context, state) => const Login(),
56-
redirect: (context, state) async {
57-
return Auth.instance.isLoggedIn ? '/profile' : null;
58-
},
59-
),
60-
GoRoute(
61-
path: "/signup",
62-
builder: (context, state) => const SignUp(),
63-
)
64-
])
65-
])
66-
]);
67+
),
68+
GoRoute(
69+
path: "/signup",
70+
builder: (context, state) => const SignUp(),
71+
)
72+
],
73+
)
74+
],
75+
)
76+
],
77+
);

dataconnect/lib/search.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import 'package:dataconnect/models/movie.dart';
2-
import 'package:dataconnect/movies_connector/movies.dart';
3-
import 'package:dataconnect/widgets/list_actors.dart';
4-
import 'package:dataconnect/widgets/list_movies.dart';
51
import 'package:flutter/material.dart';
62
import 'package:intl/intl.dart';
73

4+
import 'models/movie.dart';
5+
import 'movies_connector/movies.dart';
6+
import 'widgets/list_actors.dart';
7+
import 'widgets/list_movies.dart';
8+
89
class Search extends StatefulWidget {
910
const Search({super.key});
1011

0 commit comments

Comments
 (0)