feat(chat): text field

This commit is contained in:
mso7nueh
2024-06-11 15:38:59 +03:00
parent 1d47e28202
commit 46d374d87e
4 changed files with 125 additions and 44 deletions

View File

@@ -72,28 +72,29 @@ class MyApp extends StatelessWidget {
child: BlocBuilder<ThemeBloc, ThemeState>(
builder: (context, state) {
return KeyboardDismisser(
gestures: [
GestureType.onTap,
GestureType.onPanUpdateDownDirection,
gestures: [
GestureType.onTap,
GestureType.onPanUpdateDownDirection,
],
child: MaterialApp.router(
theme: theme,
title: 'Eatvio',
routerConfig: AppRouter.appRouter,
debugShowCheckedModeBanner: false,
localizationsDelegates: [
AppLocalizationDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
child: MaterialApp.router(
theme: theme,
title: 'Eatvio',
routerConfig: AppRouter.appRouter,
debugShowCheckedModeBanner: false,
localizationsDelegates: [
AppLocalizationDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [
Locale(
'ru',
'',
),
],
));
supportedLocales: [
Locale(
'ru',
'',
),
],
),
);
},
),
);

View File

@@ -14,6 +14,7 @@ class ChatState extends Equatable {
@override
List<Object?> get props => [chatModelObj];
ChatState copyWith({ChatModel? chatModelObj}) {
return ChatState(
chatModelObj: chatModelObj ?? this.chatModelObj,
@@ -29,8 +30,8 @@ class ChatLoadedState extends ChatState {
@override
List<Object?> get props => [chatModelObj, messages];
ChatLoadedState copyWith(
{ChatModel? chatModelObj, List<ChatMessageModel>? messages}) {
ChatLoadedState copyWith({ChatModel? chatModelObj, List<ChatMessageModel>? messages}) {
return ChatLoadedState(
chatModelObj: chatModelObj ?? this.chatModelObj,
messages: messages ?? this.messages,
@@ -48,6 +49,5 @@ class ChatErrorState extends ChatState {
}
class ChatInitialState extends ChatState {
ChatInitialState({required ChatModel chatModelObj})
: super(chatModelObj: chatModelObj);
ChatInitialState({required ChatModel chatModelObj}) : super(chatModelObj: chatModelObj);
}

View File

@@ -13,10 +13,12 @@ class ChatScreen extends StatelessWidget {
static Widget builder(BuildContext context, chatID) {
return BlocProvider<ChatBloc>(
create: (context) => ChatBloc(
ChatState(chatModelObj: ChatModel(chatID: chatID.toString())))
..add(ChatInitialEvent()),
child: ChatScreen());
create: (context) => ChatBloc(ChatState(chatModelObj: ChatModel(chatID: chatID.toString())))
..add(
ChatInitialEvent(),
),
child: ChatScreen(),
);
}
Widget build(BuildContext context) {
@@ -24,7 +26,9 @@ class ChatScreen extends StatelessWidget {
builder: (context, state) {
if (state is ChatInitialState) {
return Scaffold(
body: Center(child: CircularProgressIndicator(),),
body: Center(
child: CircularProgressIndicator(),
),
);
} else if (state is ChatLoadedState) {
// Данные загружены, можно строить экран.
@@ -34,7 +38,9 @@ class ChatScreen extends StatelessWidget {
return Center(child: Text(state.errorMessage));
} else {
return Scaffold(
body: Center(child: CircularProgressIndicator(),),
body: Center(
child: CircularProgressIndicator(),
),
);
}
},
@@ -44,25 +50,98 @@ class ChatScreen extends StatelessWidget {
_buildChat(BuildContext context, ChatLoadedState state) {
mediaQueryData = MediaQuery.of(context);
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: _buildAppbar(context),
resizeToAvoidBottomInset: true,
appBar: _buildAppbar(context, state),
body: SizedBox(
width: double.maxFinite,
child: Container(
width: double.maxFinite,
decoration: AppDecoration.fillGray,
child: ListView(
children: [
SizedBox(height: 30.v),
],
),
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) {
_buildAppbar(BuildContext context, ChatLoadedState state) {
return CustomAppBar(
leadingWidth: 26.h,
leading: AppbarLeadingImage(
@@ -87,7 +166,7 @@ class ChatScreen extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AppbarSubtitle(
text: "Валерий Леонтьев",
text: 'username',
),
SizedBox(height: 3.v),
Text("Был в сети вчера", style: theme.textTheme.bodySmall!)

View File

@@ -11,7 +11,7 @@ dependencies:
flutter_bloc: ^8.0.0
connectivity_plus: ^5.0.2
shared_preferences: ^2.0.15
cached_network_image: ^3.2.1
cached_network_image: ^3.3.1
flutter_svg: ^2.0.9
equatable: ^2.0.0
validators: ^3.0.0
@@ -36,6 +36,7 @@ dev_dependencies:
dart_code_metrics_presets: ^1.8.0
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets: