create simple chat view

This commit is contained in:
otsmr 2025-01-20 00:12:04 +01:00
parent d152240c16
commit 809f677626
6 changed files with 255 additions and 4 deletions

View file

@ -0,0 +1,118 @@
// import 'package:camera/camera.dart';
// import 'camera_editor_view.dart';
// import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:camerawesome/camerawesome_plugin.dart';
class CameraPreviewView extends StatelessWidget {
const CameraPreviewView({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'Custom CamerAwesome UI',
home: CameraPage(),
);
}
}
class CameraPage extends StatelessWidget {
const CameraPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: CameraAwesomeBuilder.awesome(
saveConfig: SaveConfig.photo(),
sensorConfig: SensorConfig.single(
sensor: Sensor.position(SensorPosition.back),
aspectRatio: CameraAspectRatios.ratio_1_1,
),
previewFit: CameraPreviewFit.contain,
previewPadding: const EdgeInsets.only(left: 150, top: 100),
previewAlignment: Alignment.topRight,
// Buttons of CamerAwesome UI will use this theme
theme: AwesomeTheme(
bottomActionsBackgroundColor: Colors.cyan.withOpacity(0.5),
buttonTheme: AwesomeButtonTheme(
backgroundColor: Colors.cyan.withOpacity(0.5),
iconSize: 20,
foregroundColor: Colors.white,
padding: const EdgeInsets.all(16),
// Tap visual feedback (ripple, bounce...)
buttonBuilder: (child, onTap) {
return ClipOval(
child: Material(
color: Colors.transparent,
shape: const CircleBorder(),
child: InkWell(
splashColor: Colors.cyan,
highlightColor: Colors.cyan.withOpacity(0.5),
onTap: onTap,
child: child,
),
),
);
},
),
),
topActionsBuilder: (state) => AwesomeTopActions(
padding: EdgeInsets.zero,
state: state,
children: [
Expanded(
child: AwesomeFilterWidget(
state: state,
filterListPosition: FilterListPosition.aboveButton,
filterListPadding: const EdgeInsets.only(top: 8),
),
),
],
),
middleContentBuilder: (state) {
return Column(
children: [
const Spacer(),
Builder(builder: (context) {
return Container(
color: AwesomeThemeProvider.of(context)
.theme
.bottomActionsBackgroundColor,
child: const Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: EdgeInsets.only(bottom: 10, top: 10),
child: Text(
"Take your best shot!",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.italic,
),
),
),
),
);
}),
],
);
},
bottomActionsBuilder: (state) => AwesomeBottomActions(
state: state,
left: AwesomeFlashButton(
state: state,
),
right: AwesomeCameraSwitchButton(
state: state,
scale: 1.0,
onSwitchTap: (state) {
state.switchCameraSensor(
aspectRatio: state.sensorConfig.aspectRatio,
);
},
),
),
),
);
}
}

View file

@ -2,6 +2,7 @@ import 'package:camera/camera.dart';
import 'camera_editor_view.dart'; import 'camera_editor_view.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
// import 'package:camerawesome/camerawesome_plugin.dart';
import 'dart:math'; import 'dart:math';
class CameraPreviewView extends StatefulWidget { class CameraPreviewView extends StatefulWidget {

View file

@ -1,21 +1,109 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class AlignedTextBox extends StatelessWidget {
const AlignedTextBox({super.key, required this.text, required this.right});
final String text;
final bool right;
@override
Widget build(BuildContext context) {
return Align(
alignment: right ? Alignment.centerRight : Alignment.centerLeft,
child: Padding(
padding: EdgeInsets.all(10),
child: Container(
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width *
0.8, // Maximum 80% of the screen width
),
padding: EdgeInsets.symmetric(
vertical: 4, horizontal: 10), // Add some padding around the text
decoration: BoxDecoration(
color: right
? Colors.deepPurpleAccent
: Colors.blueAccent, // Set the background color
borderRadius: BorderRadius.circular(12.0), // Set border radius
),
child: Text(
text,
style: TextStyle(
color: Colors.white, // Set text color for contrast
fontSize: 17,
),
textAlign: TextAlign.left, // Center the text
),
),
),
);
}
}
/// Displays detailed information about a SampleItem. /// Displays detailed information about a SampleItem.
class SampleItemDetailsView extends StatelessWidget { class SampleItemDetailsView extends StatelessWidget {
const SampleItemDetailsView({super.key, required this.userId}); const SampleItemDetailsView({super.key, required this.userId});
final int userId; final int userId;
static const routeName = '/sample_item';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
List<List<dynamic>> messages = [
["Hallo", true],
["Wie geht's?", false],
["Das ist ein Test.", true],
["Flutter ist großartig!", false],
["Ich liebe Programmieren.", true],
["Das Wetter ist schön.", false],
["Hast du Pläne für heute?", true],
["Ich mag Pizza.", false],
["Lass uns einen Film schauen.", false],
["Das ist interessant.", false],
["Ich bin müde.", true],
["Was machst du gerade?", true],
["Ich habe ein neues Hobby.", true],
["Das ist eine lange Nachricht.", false],
["Ich freue mich auf das Wochenende.", true],
["Das ist eine zufällige Nachricht.", false],
["Ich lerne Dart.", true],
["Wie war dein Tag?", true],
["Ich genieße die Natur.", true],
["Das ist ein schöner Ort.", false],
["Meine letzte Nachricht.", false],
];
messages = messages.reversed.toList();
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text('Your Chat with $userId'), title: Text('Your Chat with $userId'),
), ),
body: const Center( body: Column(
child: Text('Hallo!'), children: [
Expanded(
child: ListView.builder(
itemCount: messages.length, // Number of items in the list
reverse: true,
itemBuilder: (context, i) {
return AlignedTextBox(
text: messages[i][0], right: messages[i][1]);
},
),
),
const SizedBox(
height: 10,
),
Padding(
padding: const EdgeInsets.only(bottom: 40, left: 10, right: 10),
child: TextField(
decoration: InputDecoration(
// border: OutlineInputBorder(),
labelText: 'Enter your message',
suffixIcon: IconButton(
icon: Icon(Icons.send),
onPressed: () {
// Handle send action
},
),
),
),
),
],
), ),
); );
} }

View file

@ -167,6 +167,9 @@ class _ChatListViewState extends State<ChatListView> {
// Extract initials from the username // Extract initials from the username
List<String> nameParts = username.split(' '); List<String> nameParts = username.split(' ');
String initials = nameParts.map((part) => part[0]).join().toUpperCase(); String initials = nameParts.map((part) => part[0]).join().toUpperCase();
if (initials.length > 2) {
initials = initials[0] + initials[1];
}
// Generate a color based on the initials (you can customize this logic) // Generate a color based on the initials (you can customize this logic)
Color avatarColor = _getColorFromInitials(initials); Color avatarColor = _getColorFromInitials(initials);

View file

@ -166,6 +166,22 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.3.5" version: "0.3.5"
camerawesome:
dependency: "direct main"
description:
name: camerawesome
sha256: "3619d5605fb14ab72c815532c1d9f635512c75df07b5a742b60a9a4b03b6081e"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
carousel_slider:
dependency: transitive
description:
name: carousel_slider
sha256: "7b006ec356205054af5beaef62e2221160ea36b90fb70a35e4deacd49d0349ae"
url: "https://pub.dev"
source: hosted
version: "5.0.0"
characters: characters:
dependency: transitive dependency: transitive
description: description:
@ -214,6 +230,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.19.0" version: "1.19.0"
colorfilter_generator:
dependency: transitive
description:
name: colorfilter_generator
sha256: ccc2995e440b1d828d55d99150e7cad64624f3cb4a1e235000de3f93cf10d35c
url: "https://pub.dev"
source: hosted
version: "0.0.8"
convert: convert:
dependency: transitive dependency: transitive
description: description:
@ -586,6 +610,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.11.1" version: "0.11.1"
matrix2d:
dependency: transitive
description:
name: matrix2d
sha256: "188718dd3bc2a31e372cfd0791b0f77f4f13ea76164147342cc378d9132949e7"
url: "https://pub.dev"
source: hosted
version: "1.0.4"
meta: meta:
dependency: transitive dependency: transitive
description: description:
@ -818,6 +850,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.3.2" version: "1.3.2"
rxdart:
dependency: transitive
description:
name: rxdart
sha256: "5c3004a4a8dbb94bd4bf5412a4def4acdaa12e12f269737a5751369e12d1a962"
url: "https://pub.dev"
source: hosted
version: "0.28.0"
shared_preferences: shared_preferences:
dependency: transitive dependency: transitive
description: description:

View file

@ -11,6 +11,7 @@ environment:
dependencies: dependencies:
camera: ^0.11.0+2 camera: ^0.11.0+2
camerawesome: ^2.1.0
collection: ^1.18.0 collection: ^1.18.0
cv: ^1.1.3 cv: ^1.1.3
fixnum: ^1.1.1 fixnum: ^1.1.1