Skip to content

Commit ac7c067

Browse files
committed
feat: join room modal
1 parent 7d3c1a5 commit ac7c067

File tree

14 files changed

+236
-44
lines changed

14 files changed

+236
-44
lines changed

lib/src/app.dart

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@ import 'package:auth/src/features/home/views/screens/home_screen.dart';
66
import 'package:flutter/material.dart';
77
import 'package:flutter_bloc/flutter_bloc.dart';
88

9-
class MyApp extends StatefulWidget {
9+
class MyApp extends StatelessWidget {
1010
static GlobalKey<NavigatorState> materialKey = GlobalKey();
1111

12-
MyApp({Key? key}) : super(key: key);
13-
14-
@override
15-
_MyAppState createState() => _MyAppState();
16-
}
17-
18-
class _MyAppState extends State<MyApp> {
1912
final appRouter = AppRouter();
2013

14+
MyApp({Key? key}) : super(key: key);
15+
2116
@override
2217
Widget build(BuildContext context) {
2318
return _InitProviders(
@@ -28,7 +23,7 @@ class _MyAppState extends State<MyApp> {
2823
onGenerateRoute: appRouter.onGenerateRoute,
2924
theme: ThemeData(
3025
primaryColor: Color(0xff4C525C),
31-
accentColor: Color(0xffFFAE48),
26+
secondaryHeaderColor: Color(0xffFFAE48),
3227
highlightColor: Color(0xff58BFE6),
3328
),
3429
),

lib/src/app_router.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:auth/src/features/auth/views/screens/login_screen.dart';
22
import 'package:auth/src/features/auth/views/screens/recover_screen.dart';
33
import 'package:auth/src/features/auth/views/screens/register_screen.dart';
44
import 'package:auth/src/features/home/views/screens/home_screen.dart';
5+
import 'package:auth/src/features/room/views/screens/room_screen.dart';
56
import 'package:auth/src/features/room/views/screens/rooms_screen.dart';
67
import 'package:flutter/material.dart';
78

@@ -18,6 +19,8 @@ class AppRouter {
1819
return RecoverScreen.route();
1920
case RoomsScreen.routeName:
2021
return RoomsScreen.route();
22+
case RoomScreen.routeName:
23+
return RoomScreen.route(settings);
2124
default:
2225
return HomeScreen.route();
2326
}

lib/src/features/auth/views/screens/login_screen.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class _LoginScreenState extends State<LoginScreen> {
4747
return Scaffold(
4848
body: CirclesBackground(
4949
backgroundColor: Colors.white,
50-
topSmallCircleColor: theme.accentColor,
50+
topSmallCircleColor: theme.secondaryHeaderColor,
5151
topMediumCircleColor: theme.primaryColor,
5252
topRightCircleColor: theme.highlightColor,
5353
bottomRightCircleColor: Colors.white,
@@ -256,7 +256,7 @@ class _FooterButtons extends StatelessWidget {
256256
RecoverScreen.routeName,
257257
),
258258
child: Text('Forgot Password'),
259-
color: theme.accentColor,
259+
color: theme.secondaryHeaderColor,
260260
)
261261
],
262262
),

lib/src/features/auth/views/screens/recover_screen.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class _RecoverScreenState extends State<RecoverScreen> {
4343
return Scaffold(
4444
body: CirclesBackground(
4545
backgroundColor: Colors.white,
46-
topSmallCircleColor: theme.accentColor,
46+
topSmallCircleColor: theme.secondaryHeaderColor,
4747
topMediumCircleColor: theme.primaryColor,
4848
topRightCircleColor: theme.highlightColor,
4949
bottomRightCircleColor: Colors.white,
@@ -167,7 +167,7 @@ class _FooterButtons extends StatelessWidget {
167167
children: [
168168
UnderlinedButton(
169169
child: Text('Sign In'),
170-
color: theme.accentColor,
170+
color: theme.secondaryHeaderColor,
171171
onPressed: () => Navigator.pushNamed(
172172
context,
173173
LoginScreen.routeName,

lib/src/features/home/views/widgets/authenticated_home.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class AuthenticatedHome extends StatelessWidget {
2020

2121
return CirclesBackground(
2222
backgroundColor: Colors.white,
23-
topSmallCircleColor: theme.accentColor,
23+
topSmallCircleColor: theme.secondaryHeaderColor,
2424
topMediumCircleColor: theme.primaryColor,
2525
topRightCircleColor: Colors.white,
2626
bottomRightCircleColor: theme.highlightColor,
@@ -73,7 +73,7 @@ class AuthenticatedHome extends StatelessWidget {
7373
children: [
7474
UnderlinedButton(
7575
child: Text('Logout'),
76-
color: theme.accentColor,
76+
color: theme.secondaryHeaderColor,
7777
onPressed: () => context.read<AuthCubit>().logout(),
7878
),
7979
UnderlinedButton(

lib/src/features/home/views/widgets/non_authenticated_home.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class NonAuthenticatedHome extends StatelessWidget {
1313

1414
return CirclesBackground(
1515
backgroundColor: Colors.white,
16-
topSmallCircleColor: theme.accentColor,
16+
topSmallCircleColor: theme.secondaryHeaderColor,
1717
topMediumCircleColor: theme.primaryColor,
1818
topRightCircleColor: Colors.white,
1919
bottomRightCircleColor: theme.highlightColor,
@@ -61,7 +61,7 @@ class NonAuthenticatedHome extends StatelessWidget {
6161
children: [
6262
UnderlinedButton(
6363
child: Text('Sign In'),
64-
color: theme.accentColor,
64+
color: theme.secondaryHeaderColor,
6565
onPressed: () => Navigator.pushNamed(
6666
context,
6767
LoginScreen.routeName,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import 'package:auth/src/features/room/logic/repository/room_repository.dart';
2+
import 'package:bloc/bloc.dart';
3+
import 'package:equatable/equatable.dart';
4+
5+
part 'room_state.dart';
6+
7+
class RoomCubit extends Cubit<RoomState> {
8+
final RoomRepository repository;
9+
10+
RoomCubit({required this.repository}) : super(RoomInitial());
11+
12+
Future<void> joinRoom(String roomId, {bool isDialog = false}) async {
13+
if (state is RoomJoinInProgress) {
14+
return;
15+
}
16+
17+
emit(RoomJoinInProgress());
18+
19+
try {
20+
await repository.joinRoom(roomId);
21+
22+
emit(RoomJoinSuccess(roomId, isDialog: isDialog));
23+
} catch (e) {
24+
emit(RoomJoinFailure());
25+
}
26+
}
27+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
part of 'room_cubit.dart';
2+
3+
abstract class RoomState extends Equatable {
4+
const RoomState();
5+
6+
@override
7+
List<Object> get props => [];
8+
}
9+
10+
class RoomInitial extends RoomState {}
11+
12+
class RoomJoinInProgress extends RoomState {}
13+
14+
class RoomJoinFailure extends RoomState {}
15+
16+
class RoomJoinSuccess extends RoomState {
17+
final String roomId;
18+
final bool isDialog;
19+
20+
RoomJoinSuccess(this.roomId, {this.isDialog = false}) : super();
21+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter/widgets.dart';
3+
4+
class RoomScreen extends StatefulWidget {
5+
static const routeName = '/room';
6+
7+
static route(RouteSettings settings) {
8+
return MaterialPageRoute(
9+
builder: (_) => RoomScreen(roomId: settings.arguments as String),
10+
);
11+
}
12+
13+
final String roomId;
14+
15+
const RoomScreen({Key? key, required this.roomId}) : super(key: key);
16+
17+
@override
18+
_RoomScreenState createState() => _RoomScreenState();
19+
}
20+
21+
class _RoomScreenState extends State<RoomScreen> {
22+
@override
23+
void initState() {
24+
super.initState();
25+
26+
27+
}
28+
29+
@override
30+
Widget build(BuildContext context) {
31+
return Scaffold(
32+
appBar: AppBar(
33+
title: Text(widget.roomId),
34+
),
35+
body: Text('Test'),
36+
);
37+
}
38+
}

lib/src/features/room/views/screens/rooms_screen.dart

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import 'package:auth/src/features/auth/logic/cubit/auth_cubit.dart';
22
import 'package:auth/src/features/auth/logic/models/user.dart';
33
import 'package:auth/src/features/room/logic/bloc/rooms_bloc.dart';
4+
import 'package:auth/src/features/room/logic/cubit/cubit/room_cubit.dart';
45
import 'package:auth/src/features/room/logic/repository/room_repository.dart';
6+
import 'package:auth/src/features/room/views/screens/room_screen.dart';
7+
import 'package:auth/src/features/room/views/widgets/dialog/join_room_dialog.dart';
58
import 'package:auth/src/features/room/views/widgets/room_tile.dart';
69
import 'package:auth/src/features/room/views/widgets/dialog/upsert_room_dialog.dart';
710
import 'package:flutter/material.dart';
@@ -11,14 +14,23 @@ class RoomsScreen extends StatelessWidget {
1114
static const String routeName = '/rooms';
1215

1316
static route() {
14-
return MaterialPageRoute(
15-
builder: (context) => BlocProvider(
16-
create: (context) => RoomsBloc(
17-
repository: RoomRepository(),
18-
)..add(RoomsLoaded()),
17+
return MaterialPageRoute(builder: (context) {
18+
final repository = RoomRepository();
19+
20+
return MultiBlocProvider(
21+
providers: [
22+
BlocProvider(
23+
create: (_) => RoomsBloc(
24+
repository: repository,
25+
)..add(RoomsLoaded()),
26+
),
27+
BlocProvider(
28+
create: (_) => RoomCubit(repository: repository),
29+
)
30+
],
1931
child: RoomsScreen(),
20-
),
21-
);
32+
);
33+
});
2234
}
2335

2436
RoomsScreen({Key? key}) : super(key: key);
@@ -48,6 +60,18 @@ class RoomsScreen extends StatelessWidget {
4860
SizedBox(
4961
height: 16,
5062
),
63+
BlocListener<RoomCubit, RoomState>(
64+
listenWhen: (_, curr) =>
65+
curr is RoomJoinSuccess && !curr.isDialog,
66+
listener: (context, state) {
67+
Navigator.pushNamed(
68+
context,
69+
RoomScreen.routeName,
70+
arguments: (state as RoomJoinSuccess).roomId,
71+
);
72+
},
73+
child: Container(),
74+
),
5175
BlocBuilder<RoomsBloc, RoomsState>(
5276
builder: (context, state) {
5377
if (state is RoomsLoadInProgress) {
@@ -165,7 +189,7 @@ class _RoomsActions extends StatelessWidget {
165189
),
166190
),
167191
TextButton(
168-
onPressed: () => {},
192+
onPressed: () => _showJoinDialog(context),
169193
child: Text(
170194
'Join Room',
171195
style: TextStyle(
@@ -189,4 +213,11 @@ class _RoomsActions extends StatelessWidget {
189213
builder: (_) => UpsertRoomDialog(bloc: context.read<RoomsBloc>()),
190214
);
191215
}
216+
217+
_showJoinDialog(BuildContext context) {
218+
return showDialog(
219+
context: context,
220+
builder: (_) => JoinRoomDialog(cubit: context.read<RoomCubit>()),
221+
);
222+
}
192223
}

0 commit comments

Comments
 (0)