Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Widget chatListSteam() {
- return Expanded(
- child: StreamBuilder(
- stream: msg.data.stream,
- builder: (BuildContext context, AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
- if (snapshot.hasError) {
- return const Center(child: Text('Something went wrong'));
- }
- if (!snapshot.hasData) {
- return const Center(
- child: CircularProgressIndicator(
- color: Colors.blueAccent,
- ),
- );
- }
- WidgetsBinding.instance.addPostFrameCallback((_) {
- _scrollController.jumpTo(_scrollController.position.maxScrollExtent);
- });
- return ListView.builder(
- controller: _scrollController,
- scrollDirection: Axis.vertical,
- shrinkWrap: true,
- cacheExtent: 500,
- keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.manual,
- physics: const ScrollPhysics(),
- padding: EdgeInsets.only(
- bottom: MediaQuery.of(context).viewInsets.bottom,
- ),
- itemCount: msg.data.length,
- itemBuilder: (ctx, index) {
- final data = msg.data[index];
- DateTime now = DateTime.now().toLocal();
- DateTime tgl = DateTime.parse(data['date_create']);
- String tglIndo = DateFormat('EEEE, dd/MM/yyyy', 'id_ID').format(tgl);
- String waktu = data['time_create'];
- String pesan = _helper.decryptStringStorage(data['pesan']);
- return Container(
- child: _helper.decryptStringStorage(data['status'].toString()) == '1'
- ? ChatBubble(
- clipper: ChatBubbleClipper1(type: BubbleType.sendBubble),
- alignment: Alignment.topRight,
- margin: const EdgeInsets.only(top: 0, bottom: 20),
- backGroundColor: Colors.blue,
- child: Container(
- constraints: BoxConstraints(
- maxWidth: MediaQuery.of(context).size.width * 1,
- ),
- child: Text(
- pesan,
- style: const TextStyle(color: Colors.white),
- ),
- ),
- )
- : Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Builder(
- builder: (context) {
- if (now.year == tgl.year && now.month == tgl.month && now.day == tgl.day) {
- return Text(
- 'Hari ini: $waktu',
- style: const TextStyle(fontSize: 10),
- );
- } else {
- Duration diff = now.difference(tgl);
- if (diff.inDays < 7) {
- return Text(
- 'Kemarin: $tglIndo - $waktu',
- style: const TextStyle(fontSize: 10),
- );
- } else if (diff.inDays > 7) {
- return Text('$tglIndo - $waktu');
- }
- }
- return Container();
- },
- ),
- ChatBubble(
- clipper: ChatBubbleClipper1(type: BubbleType.receiverBubble),
- backGroundColor: const Color(0xffE7E7ED),
- margin: const EdgeInsets.only(top: 0, bottom: 20),
- child: Container(
- constraints: BoxConstraints(
- maxWidth: MediaQuery.of(context).size.width * 1,
- ),
- child: Text(
- pesan,
- style: const TextStyle(color: Colors.black, fontSize: 14),
- ),
- ),
- ),
- ],
- ),
- );
- },
- );
- },
- ),
- );
- }
- return Scaffold(
- resizeToAvoidBottomInset: true,
- appBar: AppBar(
- elevation: 5,
- title: const Text("Mesengger"),
- ),
- body: RefreshIndicator(
- onRefresh: onLoad,
- child: ConstrainedBox(
- constraints: BoxConstraints(
- minHeight: height,
- minWidth: width,
- ),
- child: Container(
- margin: EdgeInsets.all(width * 0.03),
- padding: const EdgeInsets.all(0.0),
- color: Colors.white,
- height: height,
- width: width,
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: <Widget>[
- chatListSteam(),
- Align(
- alignment: Alignment.bottomCenter,
- child: Container(
- margin: const EdgeInsets.all(0.0),
- padding: const EdgeInsets.all(0.0),
- decoration: BoxDecoration(
- color: Theme.of(context).cardColor,
- ),
- height: 40,
- child: Row(
- children: [
- Expanded(
- child: TextFormField(
- onTap: () {},
- maxLines: 1,
- controller: _inputMsg,
- decoration: InputDecoration(
- contentPadding: const EdgeInsets.only(left: 15),
- hintText: 'Ketik pesan',
- border: OutlineInputBorder(
- borderRadius: BorderRadius.circular(35.0),
- borderSide: const BorderSide(color: Colors.grey),
- ),
- ),
- onChanged: (value) {},
- ),
- ),
- const SizedBox(
- width: 5,
- ),
- CircleAvatar(
- backgroundColor: Colors.blueAccent,
- child: IconButton(
- icon: const Icon(
- Icons.send,
- color: Colors.white,
- ),
- onPressed: () async {
- msg.kirimPesan(_inputMsg.text);
- _inputMsg.clear();
- },
- ),
- ),
- ],
- ),
- ),
- ),
- ],
- ),
- ),
- ),
- ),
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement