Skip to content

Commit

Permalink
feat: fixed layout
Browse files Browse the repository at this point in the history
  • Loading branch information
ShreyamMaity committed Mar 18, 2023
1 parent 6519ad1 commit 03d3480
Show file tree
Hide file tree
Showing 8 changed files with 487 additions and 344 deletions.
Binary file added assets/dash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
256 changes: 141 additions & 115 deletions lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,141 +22,167 @@ class _HomeScreenState extends State<HomeScreen> {
final chatHandler = ChatHandler();
final authHandler = AuthHandeler();
late user.User? currentUser;
bool _isLoading = true;

@override
void initState() {
super.initState();

authHandler.getData(email: _auth.currentUser!.email!).then((value) {
setState(() {
currentUser = value;
_isLoading = false;
});
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title: Text('Welcome ${currentUser!.username} !'),
actions: [
TextButton(
onPressed: () {
_auth.signOut();
Navigator.pushNamed(context, 'Login');
},
child: const Text(
'Logout',
style: TextStyle(color: Colors.white),
)),
],
),
body: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Expanded(
child: StreamBuilder(
stream: FirebaseFirestore.instance
.collection('chats')
.orderBy('createdAt', descending: false)
.snapshots(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(
child: CircularProgressIndicator(),
);
} else if (snapshot.hasError) {
return Text("Something Happned Wrong!");
} else if (snapshot.hasData) {
final List<Chat> chats = List.from(snapshot.data!.docs
.map((e) => Chat.fromMap(e.data()))
.toList());
return Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: ListView.builder(
shrinkWrap: true,
itemCount: chats.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(chats[index].username!),
SizedBox(
height: 10,
),
BubbleSpecialThree(
text: chats[index].message!,
color: Color(0xFF1B97F3),
tail: true,
textStyle: TextStyle(
color: Colors.white, fontSize: 16),
),
],
return _isLoading
? Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: const [
SizedBox(
height: 50,
),
CircularProgressIndicator(),
SizedBox(
height: 50,
),
Text('Fetching Current Messsages'),
],
),
),
)
: Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title: Text('Welcome ${currentUser!.username} !'),
actions: [
TextButton(
onPressed: () {
_auth.signOut();
Navigator.pushNamed(context, 'Login');
},
child: const Text(
'Logout',
style: TextStyle(color: Colors.white),
)),
],
),
body: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Expanded(
child: StreamBuilder(
stream: FirebaseFirestore.instance
.collection('chats')
.orderBy('createdAt', descending: false)
.snapshots(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(
child: CircularProgressIndicator(),
);
} else if (snapshot.hasError) {
return Text("Something Happned Wrong!");
} else if (snapshot.hasData) {
final List<Chat> chats = List.from(snapshot.data!.docs
.map((e) => Chat.fromMap(e.data()))
.toList());
return Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: ListView.builder(
shrinkWrap: true,
itemCount: chats.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment:
CrossAxisAlignment.end,
children: [
Text(chats[index].username!),
SizedBox(
height: 10,
),
BubbleSpecialThree(
text: chats[index].message!,
color: Color(0xFF1B97F3),
tail: true,
textStyle: TextStyle(
color: Colors.white,
fontSize: 16),
),
],
),
);
},
),
);
},
),
SizedBox(
height: 10,
),
],
);
} else {
return Text("Something Happned Wrong!");
}
},
),
),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 8.0, vertical: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: 320,
decoration: BoxDecoration(
border: Border.all(color: Colors.black, width: 1),
borderRadius: BorderRadius.circular(16)),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
controller: _msgController,
decoration: InputDecoration(
hintText: 'Type Your Msg',
border: InputBorder.none),
),
),
),
SizedBox(
height: 10,
),
IconButton(
onPressed: () {
if (_msgController.text == '') {
return;
} else {
chatHandler.sendMessage(
chat: Chat(
message: _msgController.text,
username: currentUser!.username,
createdAt: DateTime.now().toLocal().toString(),
));
_msgController.clear();
}
},
icon: Icon(Icons.send, color: Colors.blueAccent),
iconSize: 50,
)
],
);
} else {
return Text("Something Happned Wrong!");
}
},
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: 300,
decoration: BoxDecoration(
border: Border.all(color: Colors.black, width: 1),
borderRadius: BorderRadius.circular(16)),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
controller: _msgController,
decoration: InputDecoration(
hintText: 'Type Your Msg', border: InputBorder.none),
),
),
),
IconButton(
onPressed: () {
if (_msgController.text == '') {
return;
} else {
chatHandler.sendMessage(
chat: Chat(
message: _msgController.text,
username: currentUser!.username,
createdAt: DateTime.now().toLocal().toString(),
));
_msgController.clear();
}
},
icon: Icon(Icons.send),
iconSize: 50,
)
],
),
),
],
),
);
);
}
}
Loading

0 comments on commit 03d3480

Please sign in to comment.