0812
This commit is contained in:
171
lib/screens/part_screen.dart
Normal file
171
lib/screens/part_screen.dart
Normal file
@@ -0,0 +1,171 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:ui';
|
||||
import '../widgets/chat_box.dart';
|
||||
import '../screens/full_screen.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../services/message_service.dart';
|
||||
import '../widgets/gradient_background.dart';
|
||||
|
||||
class PartScreen extends StatefulWidget {
|
||||
final VoidCallback? onHide;
|
||||
|
||||
const PartScreen({super.key, this.onHide});
|
||||
|
||||
@override
|
||||
State<PartScreen> createState() => _PartScreenState();
|
||||
}
|
||||
|
||||
class _PartScreenState extends State<PartScreen> {
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_scrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _scrollToBottom() {
|
||||
if (_scrollController.hasClients) {
|
||||
_scrollController.animateTo(
|
||||
0.0,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.easeOut,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _openFullScreen() async {
|
||||
widget.onHide?.call();
|
||||
await Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const FullScreen(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.transparent,
|
||||
body: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final double minHeight = constraints.maxHeight * 0.18;
|
||||
final double maxHeight = constraints.maxHeight * 0.4;
|
||||
final double chatWidth = constraints.maxWidth * 0.94;
|
||||
final int messageCount =
|
||||
context.watch<MessageService>().messages.length;
|
||||
double chatHeight;
|
||||
if (messageCount <= 1) {
|
||||
chatHeight = minHeight;
|
||||
} else {
|
||||
final height = minHeight + (messageCount * 78);
|
||||
chatHeight = height < maxHeight ? height : maxHeight;
|
||||
}
|
||||
return Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: IgnorePointer(
|
||||
ignoring: false,
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.translucent,
|
||||
onTap: () {
|
||||
Provider.of<MessageService>(context, listen: false)
|
||||
.abortReply();
|
||||
if (widget.onHide != null) widget.onHide!();
|
||||
},
|
||||
child: Container(
|
||||
color: Colors.transparent,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(bottom: constraints.maxHeight * 0.22),
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: Selector<MessageService, int>(
|
||||
selector: (_, service) => service.messages.length,
|
||||
builder: (context, messageCount, child) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_scrollToBottom();
|
||||
});
|
||||
return Consumer<MessageService>(
|
||||
builder: (context, handler, child) {
|
||||
final messages = handler.messages;
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 180),
|
||||
curve: Curves.easeInOut,
|
||||
width: chatWidth,
|
||||
height: chatHeight,
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
child: BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: 12, sigmaY: 12),
|
||||
child: GradientBackground(
|
||||
colors: const [
|
||||
Color(0XBF3B0A3F),
|
||||
Color(0xBF0E0E24),
|
||||
Color(0xBF0C0B33),
|
||||
],
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: Stack(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 42,
|
||||
left: 6,
|
||||
right: 6,
|
||||
bottom: 6),
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: 12, bottom: 12),
|
||||
child: ChatBox(
|
||||
scrollController:
|
||||
_scrollController,
|
||||
messages: messages,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: 6,
|
||||
right: 6,
|
||||
child: IconButton(
|
||||
icon: const Icon(
|
||||
Icons.open_in_full,
|
||||
color: Colors.white,
|
||||
size: 24,
|
||||
),
|
||||
onPressed: _openFullScreen,
|
||||
padding: EdgeInsets.zero,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user