chat_dialog_resizable_screen.dart 4.53 KB
Newer Older
Inomjon's avatar
Inomjon committed
1 2 3 4
import 'dart:async';
import 'package:flutter/material.dart';

import 'package:connectycube_sdk/connectycube_sdk.dart';
Inomjon's avatar
Inomjon committed
5
import 'package:vmeeting/src/constants/colors_const.dart';
Inomjon's avatar
Inomjon committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
import 'package:vmeeting/srcchat/select_dialog_screen.dart';

import 'chat_dialog_screen.dart';

const double DIALOGS_LIST_WIDTH = 300;
const double MIN_SCREEN_SIZE = 800;
const double DIVIDER_WIDTH = 1;

class ChatDialogResizableScreen extends StatelessWidget {
  static const String TAG = "SelectDialogScreen";
  final CubeUser currentUser;
  final CubeDialog? selectedDialog;

  ChatDialogResizableScreen(this.currentUser, this.selectedDialog);

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () => _onBackPressed(),
      child: Scaffold(
        body: BodyLayout(currentUser, selectedDialog),
      ),
    );
  }

  Future<bool> _onBackPressed() {
    return Future.value(true);
  }
}

class BodyLayout extends StatefulWidget {
  final CubeUser currentUser;
  final CubeDialog? selectedDialog;

  BodyLayout(this.currentUser, this.selectedDialog);

  @override
  State<StatefulWidget> createState() {
    return _BodyLayoutState(currentUser, selectedDialog);
  }
}

class _BodyLayoutState extends State<BodyLayout> {
  static const String TAG = "_BodyLayoutState";

  final CubeUser currentUser;
  CubeDialog? selectedDialog;

  _BodyLayoutState(this.currentUser, CubeDialog? selectedDialog) {
    this.selectedDialog = selectedDialog;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: MediaQuery.of(context).size.height,
      child: Row(
        children: [
          if (isBigScreen || selectedDialog == null)
            LayoutBuilder(builder: (context, constraint) {
              var width = MediaQuery.of(context).size.width;

              return SizedBox(
                width: isBigScreen
                    ? width / 4 <= DIALOGS_LIST_WIDTH
                        ? DIALOGS_LIST_WIDTH
                        : width / 4
                    : width,
                child: SelectDialogScreen(selectedDialog,
                    (selectedDialog) {
                  setState(() {
                    this.selectedDialog = null;
                    Future.delayed(Duration(milliseconds: 50), () {
                      setState(() {
                        this.selectedDialog = selectedDialog;
                      });
                    });
                  });
                }),
              );
            }),
          Visibility(
            visible: isBigScreen,
            child: const VerticalDivider(
              width: DIVIDER_WIDTH,
            ),
          ),
          getSelectedDialog()
        ],
      ),
    );
  }

  Widget getSelectedDialog() {
    if (selectedDialog != null) {
      return Flexible(
        child: Stack(
          children: [
            ChatDialogScreen(currentUser, selectedDialog!),
            Align(
              alignment: Alignment.topCenter,
              child: SizedBox(
                height: AppBar().preferredSize.height,
                child: AppBar(
                  elevation: 0,
                  automaticallyImplyLeading: false,
                  leading: !isBigScreen && selectedDialog != null
                      ? IconButton(
Inomjon's avatar
Inomjon committed
114
                          icon:  Icon(Icons.arrow_back, color: ColorConst.appBleckColor),
Inomjon's avatar
Inomjon committed
115 116 117 118 119 120 121 122 123 124 125 126 127
                          onPressed: () {
                            Navigator.pop(context);
                          },
                        )
                      : null,
                  title: Text(
                    selectedDialog?.name ?? '',
                  ),
                  centerTitle: false,
                  actions: <Widget>[
                    IconButton(
                      onPressed: () => showChatDetails(
                          context, currentUser, selectedDialog!),
Inomjon's avatar
Inomjon committed
128
                      icon:  Icon(
Inomjon's avatar
Inomjon committed
129
                        Icons.info_outline,
Inomjon's avatar
Inomjon committed
130
                        color:  ColorConst.appBleckColor,
Inomjon's avatar
Inomjon committed
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      );
    } else if (isBigScreen) {
      return Expanded(
        child: Container(
          margin: EdgeInsets.only(top: AppBar().preferredSize.height),
          child: const Center(
            child: Text(
              'No dialog selected',
              style: TextStyle(fontSize: 20),
            ),
          ),
        ),
      );
    } else {
      return Container();
    }
  }

  get isBigScreen => MediaQuery.of(context).size.width >= MIN_SCREEN_SIZE;
}