Skip to content

Commit 8ad4ed0

Browse files
committed
updating widgets
1 parent 9a52d95 commit 8ad4ed0

File tree

6 files changed

+276
-297
lines changed

6 files changed

+276
-297
lines changed

dataconnect/lib/actor_detail.dart

Lines changed: 66 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,77 @@
1-
import 'package:dataconnect/movie_state.dart';
2-
import 'package:dataconnect/movies_connector/movies.dart';
3-
import 'package:dataconnect/widgets/list_movies.dart';
41
import 'package:flutter/material.dart';
52

6-
class ActorDetail extends StatefulWidget {
7-
const ActorDetail({super.key, required this.actorId});
3+
import 'movie_state.dart';
4+
import 'widgets/list_movies.dart';
85

9-
final String actorId;
6+
class ActorDetail extends StatelessWidget {
7+
const ActorDetail({
8+
super.key,
9+
required this.actorId,
10+
});
1011

11-
@override
12-
State<ActorDetail> createState() => _ActorDetailState();
13-
}
14-
15-
class _ActorDetailState extends State<ActorDetail> {
16-
bool loading = true;
17-
GetActorByIdActor? actor;
18-
@override
19-
void initState() {
20-
super.initState();
21-
22-
MovieState.getActorById(widget.actorId).then((value) {
23-
setState(() {
24-
loading = false;
25-
actor = value.data.actor;
26-
});
27-
});
28-
}
29-
30-
_buildActorInfo() {
31-
return [
32-
Align(
33-
alignment: Alignment.centerLeft,
34-
child: Container(
35-
child: Text(
36-
actor!.name,
37-
style: const TextStyle(fontSize: 30),
38-
),
39-
)),
40-
Row(
41-
mainAxisAlignment: MainAxisAlignment.start,
42-
crossAxisAlignment: CrossAxisAlignment.start,
43-
children: [
44-
Expanded(
45-
child: AspectRatio(
46-
aspectRatio: 9 / 16, // 9:16 aspect ratio for the image
47-
child: Image.network(
48-
actor!.imageUrl,
49-
fit: BoxFit.cover,
50-
),
51-
),
52-
),
53-
]),
54-
];
55-
}
56-
57-
Widget _buildMainRoles() {
58-
return ListMovies(
59-
movies: MovieState.convertMainActorDetail(actor!.mainActors),
60-
title: "Main Roles");
61-
}
62-
63-
Widget _buildSupportingRoles() {
64-
return ListMovies(
65-
movies:
66-
MovieState.convertSupportingActorDetail(actor!.supportingActors),
67-
title: "Supporting Roles");
68-
}
12+
final String actorId;
6913

7014
@override
7115
Widget build(BuildContext context) {
72-
return Scaffold(
73-
body: SafeArea(
74-
child: actor == null
75-
? const Column(
76-
mainAxisAlignment: MainAxisAlignment.center,
77-
crossAxisAlignment: CrossAxisAlignment.center,
78-
children: [CircularProgressIndicator()],
79-
)
80-
: Padding(
16+
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(
8130
padding: const EdgeInsets.all(30),
8231
child: SingleChildScrollView(
83-
child: Column(
84-
children: [
85-
..._buildActorInfo(),
86-
_buildMainRoles(),
87-
_buildSupportingRoles()
88-
],
89-
)))),
90-
);
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+
),
52+
),
53+
),
54+
],
55+
),
56+
ListMovies(
57+
movies: MovieState.convertMainActorDetail(
58+
actor.mainActors,
59+
),
60+
title: "Main Roles",
61+
),
62+
ListMovies(
63+
movies: MovieState.convertSupportingActorDetail(
64+
actor.supportingActors,
65+
),
66+
title: "Supporting Roles",
67+
),
68+
],
69+
),
70+
),
71+
);
72+
}(),
73+
),
74+
);
75+
});
9176
}
9277
}

dataconnect/lib/login.dart

Lines changed: 75 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:dataconnect/movies_connector/movies.dart';
21
import 'package:firebase_auth/firebase_auth.dart';
32
import 'package:flutter/material.dart';
43
import 'package:go_router/go_router.dart';
@@ -14,75 +13,24 @@ class _LoginState extends State<Login> {
1413
final _formKey = GlobalKey<FormState>();
1514
String _username = '';
1615
String _password = '';
17-
Widget _buildForm() {
18-
return Form(
19-
key: _formKey,
20-
child: Column(
21-
children: [
22-
TextFormField(
23-
decoration: const InputDecoration(
24-
hintText: "Username", border: OutlineInputBorder()),
25-
onChanged: (value) {
26-
setState(() {
27-
_username = value;
28-
});
29-
},
30-
validator: (value) {
31-
if (value == null || value.isEmpty) {
32-
return 'Please enter some text';
33-
}
34-
return null;
35-
},
36-
),
37-
const SizedBox(height: 30),
38-
TextFormField(
39-
obscureText: true,
40-
autocorrect: false,
41-
decoration: const InputDecoration(
42-
hintText: "Password", border: OutlineInputBorder()),
43-
onChanged: (value) {
44-
setState(() {
45-
_password = value;
46-
});
47-
},
48-
validator: (value) {
49-
if (value == null || value.isEmpty) {
50-
return 'Please enter a password';
51-
}
5216

53-
return null;
54-
},
55-
),
56-
ElevatedButton(
57-
onPressed: () {
58-
if (_formKey.currentState!.validate()) {
59-
logIn();
60-
}
61-
},
62-
child: const Text('Sign In')),
63-
Text('Don\'t have an account?'),
64-
ElevatedButton(
65-
onPressed: () {
66-
context.go('/signup');
67-
},
68-
child: const Text('Sign Up')),
69-
],
70-
));
71-
}
72-
73-
logIn() async {
74-
ScaffoldMessenger.of(context)
75-
.showSnackBar(const SnackBar(content: Text('Signing In')));
17+
Future<void> logIn(BuildContext context) async {
18+
final messenger = ScaffoldMessenger.of(context);
19+
final navigator = GoRouter.of(context);
20+
messenger.showSnackBar(const SnackBar(content: Text('Signing In')));
7621
try {
77-
await FirebaseAuth.instance
78-
.signInWithEmailAndPassword(email: _username, password: _password);
22+
await FirebaseAuth.instance.signInWithEmailAndPassword(
23+
email: _username,
24+
password: _password,
25+
);
7926
if (mounted) {
80-
context.go('/home');
27+
navigator.go('/home');
8128
}
8229
} catch (_) {
8330
if (mounted) {
84-
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
85-
content: Text('There was an error when creating a user.')));
31+
messenger.showSnackBar(const SnackBar(
32+
content: Text('There was an error when creating a user.'),
33+
));
8634
}
8735
}
8836
}
@@ -91,13 +39,70 @@ class _LoginState extends State<Login> {
9139
Widget build(BuildContext context) {
9240
return Scaffold(
9341
body: SafeArea(
94-
child: Padding(
95-
padding: EdgeInsets.all(30),
42+
child: Padding(
43+
padding: const EdgeInsets.all(30),
44+
child: Center(
45+
child: Form(
46+
key: _formKey,
9647
child: Column(
97-
mainAxisAlignment: MainAxisAlignment.center,
98-
crossAxisAlignment: CrossAxisAlignment.center,
99-
children: [_buildForm()],
100-
))),
48+
children: [
49+
TextFormField(
50+
decoration: const InputDecoration(
51+
hintText: "Username",
52+
border: OutlineInputBorder(),
53+
),
54+
onChanged: (value) {
55+
setState(() {
56+
_username = value;
57+
});
58+
},
59+
validator: (value) {
60+
if (value == null || value.isEmpty) {
61+
return 'Please enter some text';
62+
}
63+
return null;
64+
},
65+
),
66+
const SizedBox(height: 30),
67+
TextFormField(
68+
obscureText: true,
69+
autocorrect: false,
70+
decoration: const InputDecoration(
71+
hintText: "Password",
72+
border: OutlineInputBorder(),
73+
),
74+
onChanged: (value) {
75+
setState(() {
76+
_password = value;
77+
});
78+
},
79+
validator: (value) {
80+
if (value == null || value.isEmpty) {
81+
return 'Please enter a password';
82+
}
83+
return null;
84+
},
85+
),
86+
ElevatedButton(
87+
onPressed: () {
88+
if (_formKey.currentState!.validate()) {
89+
logIn(context);
90+
}
91+
},
92+
child: const Text('Sign In')),
93+
const Text("Don't have an account?"),
94+
ElevatedButton(
95+
onPressed: () {
96+
context.go('/signup');
97+
},
98+
child: const Text('Sign Up'),
99+
),
100+
],
101+
),
102+
),
103+
),
104+
),
105+
),
101106
);
102107
}
103108
}

dataconnect/lib/main.dart

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import 'package:dataconnect/models/movie.dart';
2-
import 'package:dataconnect/movie_state.dart';
3-
import 'package:dataconnect/router.dart';
4-
import 'package:dataconnect/widgets/list_movies.dart';
51
import 'package:firebase_auth/firebase_auth.dart';
62
import 'package:flutter/material.dart';
73
import 'package:firebase_core/firebase_core.dart';
84
import 'firebase_options.dart';
95
import 'movies_connector/movies.dart';
6+
import 'models/movie.dart';
7+
import 'movie_state.dart';
8+
import 'router.dart';
9+
import 'widgets/list_movies.dart';
1010

1111
void main() async {
1212
WidgetsFlutterBinding.ensureInitialized();
@@ -69,21 +69,25 @@ class _MyHomePageState extends State<MyHomePage> {
6969
child: Column(
7070
children: <Widget>[
7171
ListMovies(
72-
title: 'Top 10 Movies',
73-
movies: _topMovies
74-
.map(
75-
(e) =>
76-
Movie(id: e.id, title: e.title, imageUrl: e.imageUrl),
77-
)
78-
.toList()),
72+
title: 'Top 10 Movies',
73+
movies: _topMovies
74+
.map((e) => Movie(
75+
id: e.id,
76+
title: e.title,
77+
imageUrl: e.imageUrl,
78+
))
79+
.toList(),
80+
),
7981
ListMovies(
80-
title: 'Latest Movies',
81-
movies: _latestMovies
82-
.map(
83-
(e) =>
84-
Movie(id: e.id, title: e.title, imageUrl: e.imageUrl),
85-
)
86-
.toList()),
82+
title: 'Latest Movies',
83+
movies: _latestMovies
84+
.map((e) => Movie(
85+
id: e.id,
86+
title: e.title,
87+
imageUrl: e.imageUrl,
88+
))
89+
.toList(),
90+
),
8791
],
8892
),
8993
)),

0 commit comments

Comments
 (0)