forked from eatvio/eatvio_app
193 lines
5.8 KiB
Dart
193 lines
5.8 KiB
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';
|
|
import 'package:eatvio_app/widgets/app_bar/appbar_title_image.dart';
|
|
import 'package:eatvio_app/widgets/custom_bottom_bar.dart';
|
|
import 'package:eatvio_app/widgets/custom_text_form_field.dart';
|
|
|
|
class ChatScreen extends StatelessWidget {
|
|
const ChatScreen({Key? key}) : super(key: key);
|
|
static Widget builder(BuildContext context) {
|
|
final chatID = ModalRoute.of(context)!.settings.arguments;
|
|
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 Container(
|
|
color: Colors.white,
|
|
);
|
|
} else if (state is ChatLoadedState) {
|
|
// Данные загружены, можно строить экран.
|
|
return _buildChat(context, state);
|
|
} else if (state is ChatErrorState) {
|
|
// Произошла ошибка при загрузке данных.
|
|
return Center(child: Text(state.errorMessage));
|
|
} else {
|
|
// Другие состояния, если они есть.
|
|
return Container(); // Пустой контейнер для необработанных состояний.
|
|
}
|
|
},
|
|
);
|
|
}
|
|
|
|
_buildChat(BuildContext context, ChatLoadedState state) {
|
|
mediaQueryData = MediaQuery.of(context);
|
|
return Scaffold(
|
|
resizeToAvoidBottomInset: false,
|
|
appBar: _buildAppbar(context),
|
|
body: SizedBox(
|
|
width: double.maxFinite,
|
|
child: Container(
|
|
width: double.maxFinite,
|
|
decoration: AppDecoration.fillGray,
|
|
child: ListView(
|
|
children: [
|
|
SizedBox(height: 30.v),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
bottomNavigationBar: _buildTextField(context),
|
|
);
|
|
}
|
|
|
|
/// Section Widget
|
|
_buildAppbar(BuildContext context) {
|
|
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: [
|
|
AppbarTitleImage(
|
|
imagePath: ImageConstant.imgIconMoreHorizontal,
|
|
margin: EdgeInsets.only(bottom: 3.v),
|
|
),
|
|
Padding(
|
|
padding: EdgeInsets.only(
|
|
left: 12.h,
|
|
top: 2.v,
|
|
),
|
|
child: Column(
|
|
children: [
|
|
AppbarSubtitle(
|
|
text: "Валерий Леонтьев",
|
|
),
|
|
SizedBox(height: 3.v),
|
|
Text("Был в сети вчера", style: theme.textTheme.bodySmall!)
|
|
],
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Section Widget
|
|
_buildTextField(BuildContext context) {
|
|
return Container(
|
|
width: double.maxFinite,
|
|
padding: EdgeInsets.symmetric(
|
|
horizontal: 7.h,
|
|
vertical: 6.v,
|
|
),
|
|
decoration: AppDecoration.outlineBlueGray,
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
CustomImageView(
|
|
imagePath: ImageConstant.imgAttach,
|
|
height: 29.adaptSize,
|
|
width: 29.adaptSize,
|
|
margin: EdgeInsets.only(
|
|
top: 1.v,
|
|
bottom: 6.v,
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Padding(
|
|
padding: EdgeInsets.only(
|
|
left: 4.h,
|
|
bottom: 4.v,
|
|
),
|
|
child: BlocSelector<ChatBloc, ChatState, TextEditingController?>(
|
|
selector: (state) => TextEditingController(),
|
|
builder: (context, messageController) {
|
|
return CustomTextFormField(
|
|
controller: messageController,
|
|
hintText: "Напишите сообщение...",
|
|
textInputAction: TextInputAction.done,
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
CustomImageView(
|
|
imagePath: ImageConstant.imgMic,
|
|
height: 24.v,
|
|
width: 18.h,
|
|
margin: EdgeInsets.only(
|
|
left: 11.h,
|
|
top: 4.v,
|
|
bottom: 8.v,
|
|
),
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Common widget
|
|
|
|
///Handling route based on bottom click actions
|
|
String getCurrentRoute(BottomBarEnum type) {
|
|
switch (type) {
|
|
case BottomBarEnum.tf:
|
|
return AppRoutes.chatScreen;
|
|
default:
|
|
return "/";
|
|
}
|
|
}
|
|
|
|
///Handling page based on route
|
|
Widget getCurrentPage(
|
|
BuildContext context,
|
|
String currentRoute,
|
|
) {
|
|
switch (currentRoute) {
|
|
case AppRoutes.chatScreen:
|
|
return ChatScreen.builder(context);
|
|
default:
|
|
return ChatScreen();
|
|
}
|
|
}
|
|
|
|
/// Navigates to the previous screen.
|
|
onTapArrowleftone(BuildContext context) {
|
|
NavigatorService.goBack();
|
|
}
|
|
}
|