remember chat window last position

Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com>
This commit is contained in:
Sahil Yeole 2023-09-04 01:45:48 +05:30
parent 969eeff636
commit 9cce56caf8
2 changed files with 21 additions and 6 deletions

View File

@ -16,7 +16,8 @@ class DraggableChatWindow extends StatelessWidget {
this.position = Offset.zero, this.position = Offset.zero,
required this.width, required this.width,
required this.height, required this.height,
required this.chatModel}) required this.chatModel
})
: super(key: key); : super(key: key);
final Offset position; final Offset position;
@ -48,6 +49,7 @@ class DraggableChatWindow extends StatelessWidget {
position: position, position: position,
width: width, width: width,
height: height, height: height,
chatModel: chatModel,
builder: (context, onPanUpdate) { builder: (context, onPanUpdate) {
final child = final child =
Scaffold( Scaffold(
@ -242,6 +244,7 @@ class Draggable extends StatefulWidget {
this.position = Offset.zero, this.position = Offset.zero,
required this.width, required this.width,
required this.height, required this.height,
this.chatModel,
required this.builder}) required this.builder})
: super(key: key); : super(key: key);
@ -250,6 +253,7 @@ class Draggable extends StatefulWidget {
final Offset position; final Offset position;
final double width; final double width;
final double height; final double height;
final ChatModel? chatModel;
final Widget Function(BuildContext, GestureDragUpdateCallback) builder; final Widget Function(BuildContext, GestureDragUpdateCallback) builder;
@override @override
@ -258,6 +262,7 @@ class Draggable extends StatefulWidget {
class _DraggableState extends State<Draggable> { class _DraggableState extends State<Draggable> {
late Offset _position; late Offset _position;
late ChatModel? _chatModel;
bool _keyboardVisible = false; bool _keyboardVisible = false;
double _saveHeight = 0; double _saveHeight = 0;
double _lastBottomHeight = 0; double _lastBottomHeight = 0;
@ -266,6 +271,7 @@ class _DraggableState extends State<Draggable> {
void initState() { void initState() {
super.initState(); super.initState();
_position = widget.position; _position = widget.position;
_chatModel = widget.chatModel??null;
} }
void onPanUpdate(DragUpdateDetails d) { void onPanUpdate(DragUpdateDetails d) {
@ -292,6 +298,7 @@ class _DraggableState extends State<Draggable> {
setState(() { setState(() {
_position = Offset(x, y); _position = Offset(x, y);
}); });
_chatModel?.setChatWindowPosition(_position);
} }
checkScreenSize() {} checkScreenSize() {}
@ -351,14 +358,14 @@ class IOSDraggable extends StatefulWidget {
const IOSDraggable({ const IOSDraggable({
Key? key, Key? key,
this.position = Offset.zero, this.position = Offset.zero,
required this.chatModel, this.chatModel,
required this.width, required this.width,
required this.height, required this.height,
required this.builder}) required this.builder})
: super(key: key); : super(key: key);
final Offset position; final Offset position;
final ChatModel chatModel; final ChatModel? chatModel;
final double width; final double width;
final double height; final double height;
final Widget Function(BuildContext) builder; final Widget Function(BuildContext) builder;
@ -369,7 +376,7 @@ class IOSDraggable extends StatefulWidget {
class _IOSDraggableState extends State<IOSDraggable> { class _IOSDraggableState extends State<IOSDraggable> {
late Offset _position; late Offset _position;
late ChatModel _chatModel; late ChatModel? _chatModel;
late double _width; late double _width;
late double _height; late double _height;
@ -377,7 +384,7 @@ late double _height;
void initState() { void initState() {
super.initState(); super.initState();
_position = widget.position; _position = widget.position;
_chatModel = widget.chatModel; _chatModel = widget.chatModel??null;
_width = widget.width; _width = widget.width;
_height = widget.height; _height = widget.height;
} }
@ -394,6 +401,7 @@ void initState() {
setState(() { setState(() {
_position += details.delta; _position += details.delta;
}); });
_chatModel?.setChatWindowPosition(_position);
}, },
child: Material( child: Material(
child: child:

View File

@ -72,6 +72,13 @@ class ChatModel with ChangeNotifier {
RxInt mobileUnreadSum = 0.obs; RxInt mobileUnreadSum = 0.obs;
MessageKey? latestReceivedKey; MessageKey? latestReceivedKey;
Offset chatWindowPosition = Offset(20, 80);
void setChatWindowPosition(Offset position) {
chatWindowPosition = position;
notifyListeners();
}
@override @override
void dispose() { void dispose() {
textController.dispose(); textController.dispose();
@ -210,7 +217,7 @@ class ChatModel with ChangeNotifier {
} }
}, },
child: DraggableChatWindow( child: DraggableChatWindow(
position: chatInitPos ?? Offset(20, 80), position: chatInitPos ?? chatWindowPosition,
width: 250, width: 250,
height: 350, height: 350,
chatModel: this)); chatModel: this));