forked from eatvio/eatvio_app
187 lines
5.9 KiB
Dart
187 lines
5.9 KiB
Dart
import 'package:go_router/go_router.dart';
|
|
|
|
import 'bloc/chat_bloc.dart';
|
|
import 'models/chat_model.dart';
|
|
import 'package:eatvio_app/core/app_export.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:eatvio_app/widgets/app_bar/custom_app_bar.dart';
|
|
import 'package:eatvio_app/widgets/app_bar/appbar_subtitle.dart';
|
|
import 'package:eatvio_app/widgets/app_bar/appbar_leading_image.dart';
|
|
|
|
class ChatScreen extends StatelessWidget {
|
|
const ChatScreen({Key? key}) : super(key: key);
|
|
|
|
static Widget builder(BuildContext context, chatID) {
|
|
return BlocProvider<ChatBloc>(
|
|
create: (context) => ChatBloc(ChatState(chatModelObj: ChatModel(chatID: chatID.toString())))
|
|
..add(
|
|
ChatInitialEvent(),
|
|
),
|
|
child: ChatScreen(),
|
|
);
|
|
}
|
|
|
|
Widget build(BuildContext context) {
|
|
return BlocBuilder<ChatBloc, ChatState>(
|
|
builder: (context, state) {
|
|
if (state is ChatInitialState) {
|
|
return Scaffold(
|
|
body: Center(
|
|
child: CircularProgressIndicator(),
|
|
),
|
|
);
|
|
} else if (state is ChatLoadedState) {
|
|
// Данные загружены, можно строить экран.
|
|
return _buildChat(context, state);
|
|
} else if (state is ChatErrorState) {
|
|
// Произошла ошибка при загрузке данных.
|
|
return Center(child: Text(state.errorMessage));
|
|
} else {
|
|
return Scaffold(
|
|
body: Center(
|
|
child: CircularProgressIndicator(),
|
|
),
|
|
);
|
|
}
|
|
},
|
|
);
|
|
}
|
|
|
|
_buildChat(BuildContext context, ChatLoadedState state) {
|
|
mediaQueryData = MediaQuery.of(context);
|
|
return Scaffold(
|
|
resizeToAvoidBottomInset: true,
|
|
appBar: _buildAppbar(context, state),
|
|
body: SizedBox(
|
|
width: double.maxFinite,
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Container(
|
|
width: double.maxFinite,
|
|
decoration: AppDecoration.fillGray,
|
|
child: ListView(
|
|
shrinkWrap: true,
|
|
children: [
|
|
for (int i = 0; i < state.messages!.length; i++) ...[Text(state.messages![i].data)]
|
|
],
|
|
),
|
|
),
|
|
const Spacer(),
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
SizedBox(width: 8),
|
|
InkWell(
|
|
onTap: () {},
|
|
borderRadius: BorderRadius.circular(16),
|
|
child: Ink(
|
|
height: 32,
|
|
width: 32,
|
|
child: Icon(
|
|
Icons.attach_file_rounded,
|
|
size: 28,
|
|
),
|
|
),
|
|
),
|
|
SizedBox(width: 8),
|
|
SizedBox(
|
|
width: mediaQueryData.size.width - 96,
|
|
child: TextFormField(
|
|
maxLines: 5,
|
|
minLines: 1,
|
|
keyboardType: TextInputType.multiline,
|
|
decoration: InputDecoration(
|
|
contentPadding: EdgeInsets.symmetric(horizontal: 8, vertical: 0),
|
|
hintText: 'Сообщение',
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(16),
|
|
borderSide: BorderSide(
|
|
color: Color(0xFFD1D1D6),
|
|
width: 1,
|
|
),
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(16),
|
|
borderSide: BorderSide(
|
|
color: Color(0xFFD1D1D6),
|
|
width: 1,
|
|
),
|
|
),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(16),
|
|
borderSide: BorderSide(
|
|
color: Color(0xFFD1D1D6),
|
|
width: 1,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
SizedBox(width: 8),
|
|
InkWell(
|
|
borderRadius: BorderRadius.circular(16),
|
|
onTap: () {},
|
|
child: Ink(
|
|
height: 32,
|
|
width: 32,
|
|
child: Icon(
|
|
Icons.send,
|
|
size: 28,
|
|
),
|
|
),
|
|
),
|
|
SizedBox(width: 8),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Section Widget
|
|
_buildAppbar(BuildContext context, ChatLoadedState state) {
|
|
return CustomAppBar(
|
|
leadingWidth: 26.h,
|
|
leading: AppbarLeadingImage(
|
|
imagePath: ImageConstant.imgArrowLeft,
|
|
margin: EdgeInsets.only(
|
|
left: 16.h,
|
|
top: 18.v,
|
|
bottom: 25.v,
|
|
),
|
|
onTap: () => onTapArrowleftone(context),
|
|
),
|
|
title: Padding(
|
|
padding: EdgeInsets.only(left: 12.h),
|
|
child: Row(
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets.only(
|
|
left: 12.h,
|
|
top: 2.v,
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
AppbarSubtitle(
|
|
text: 'username',
|
|
),
|
|
SizedBox(height: 3.v),
|
|
Text("Был в сети вчера", style: theme.textTheme.bodySmall!)
|
|
],
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Navigates to the previous screen.
|
|
onTapArrowleftone(BuildContext context) {
|
|
GoRouter.of(context).pop();
|
|
}
|
|
}
|