Skip to content

Commit

Permalink
Fixes after PR
Browse files Browse the repository at this point in the history
  • Loading branch information
demchenkoalex committed May 16, 2023
1 parent 3347c67 commit 2368933
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 216 deletions.
1 change: 0 additions & 1 deletion example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
.history
.svn/
migrate_working_dir/
google-services.json

# IntelliJ related
*.iml
Expand Down
54 changes: 27 additions & 27 deletions example/lib/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,6 @@ class ChatPage extends StatefulWidget {
class _ChatPageState extends State<ChatPage> {
bool _isAttachmentUploading = false;

@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
systemOverlayStyle: SystemUiOverlayStyle.light,
title: const Text('Chat'),
),
body: StreamBuilder<types.Room>(
initialData: widget.room,
stream: FirebaseChatCore.instance.room(widget.room.id),
builder: (context, snapshot) => StreamBuilder<List<types.Message>>(
initialData: const [],
stream: FirebaseChatCore.instance.messages(snapshot.data!),
builder: (context, snapshot) => Chat(
isAttachmentUploading: _isAttachmentUploading,
messages: snapshot.data ?? [],
onAttachmentPressed: _handleAtachmentPressed,
onMessageTap: _handleMessageTap,
onPreviewDataFetched: _handlePreviewDataFetched,
onSendPressed: _handleSendPressed,
user: types.User(
id: FirebaseChatCore.instance.firebaseUser?.uid ?? '',
),
),
),
),
);

void _handleAtachmentPressed() {
showModalBottomSheet<void>(
context: context,
Expand Down Expand Up @@ -224,4 +197,31 @@ class _ChatPageState extends State<ChatPage> {
_isAttachmentUploading = uploading;
});
}

@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
systemOverlayStyle: SystemUiOverlayStyle.light,
title: const Text('Chat'),
),
body: StreamBuilder<types.Room>(
initialData: widget.room,
stream: FirebaseChatCore.instance.room(widget.room.id),
builder: (context, snapshot) => StreamBuilder<List<types.Message>>(
initialData: const [],
stream: FirebaseChatCore.instance.messages(snapshot.data!),
builder: (context, snapshot) => Chat(
isAttachmentUploading: _isAttachmentUploading,
messages: snapshot.data ?? [],
onAttachmentPressed: _handleAtachmentPressed,
onMessageTap: _handleMessageTap,
onPreviewDataFetched: _handlePreviewDataFetched,
onSendPressed: _handleSendPressed,
user: types.User(
id: FirebaseChatCore.instance.firebaseUser?.uid ?? '',
),
),
),
),
);
}
78 changes: 39 additions & 39 deletions example/lib/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,45 @@ class _LoginPageState extends State<LoginPage> {
_usernameController = TextEditingController(text: '');
}

void _login() async {
FocusScope.of(context).unfocus();

setState(() {
_loggingIn = true;
});

try {
await FirebaseAuth.instance.signInWithEmailAndPassword(
email: _usernameController!.text,
password: _passwordController!.text,
);
if (!mounted) return;
Navigator.of(context).pop();
} catch (e) {
setState(() {
_loggingIn = false;
});

await showDialog(
context: context,
builder: (context) => AlertDialog(
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('OK'),
),
],
content: Text(
e.toString(),
),
title: const Text('Error'),
),
);
}
}

@override
void dispose() {
_focusNode?.dispose();
Expand Down Expand Up @@ -116,43 +155,4 @@ class _LoginPageState extends State<LoginPage> {
),
),
);

void _login() async {
FocusScope.of(context).unfocus();

setState(() {
_loggingIn = true;
});

try {
await FirebaseAuth.instance.signInWithEmailAndPassword(
email: _usernameController!.text,
password: _passwordController!.text,
);
if (!mounted) return;
Navigator.of(context).pop();
} catch (e) {
setState(() {
_loggingIn = false;
});

await showDialog(
context: context,
builder: (context) => AlertDialog(
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('OK'),
),
],
content: Text(
e.toString(),
),
title: const Text('Error'),
),
);
}
}
}
5 changes: 4 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';

import 'firebase_options.dart';
import 'rooms.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const MyApp());
}

Expand Down
102 changes: 51 additions & 51 deletions example/lib/register.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,57 @@ class _RegisterPageState extends State<RegisterPage> {
);
}

void _register() async {
FocusScope.of(context).unfocus();

setState(() {
_registering = true;
});

try {
final credential =
await FirebaseAuth.instance.createUserWithEmailAndPassword(
email: _usernameController!.text,
password: _passwordController!.text,
);
await FirebaseChatCore.instance.createUserInFirestore(
types.User(
firstName: _firstName,
id: credential.user!.uid,
imageUrl: 'https://i.pravatar.cc/300?u=$_email',
lastName: _lastName,
),
);

if (!mounted) return;
Navigator.of(context)
..pop()
..pop();
} catch (e) {
setState(() {
_registering = false;
});

await showDialog(
context: context,
builder: (context) => AlertDialog(
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('OK'),
),
],
content: Text(
e.toString(),
),
title: const Text('Error'),
),
);
}
}

@override
void dispose() {
_focusNode?.dispose();
Expand Down Expand Up @@ -116,55 +167,4 @@ class _RegisterPageState extends State<RegisterPage> {
),
),
);

void _register() async {
FocusScope.of(context).unfocus();

setState(() {
_registering = true;
});

try {
final credential =
await FirebaseAuth.instance.createUserWithEmailAndPassword(
email: _usernameController!.text,
password: _passwordController!.text,
);
await FirebaseChatCore.instance.createUserInFirestore(
types.User(
firstName: _firstName,
id: credential.user!.uid,
imageUrl: 'https://i.pravatar.cc/300?u=$_email',
lastName: _lastName,
),
);

if (!mounted) return;
Navigator.of(context)
..pop()
..pop();
} catch (e) {
setState(() {
_registering = false;
});

await showDialog(
context: context,
builder: (context) => AlertDialog(
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('OK'),
),
],
content: Text(
e.toString(),
),
title: const Text('Error'),
),
);
}
}
}

0 comments on commit 2368933

Please sign in to comment.