在本教程中,我将向您展示如何使用 Flutter 构建一个完整的聊天应用程序。对于这一部分,我们将创建应用程序的 UI 原型,然后我将向您展示如何使用 firebase 创建后端服务并创建聊天系统。

UI的源代码

import 'package:flutter/material.dart';void main() {runApp(MaterialApp(debugShowCheckedModeBanner: false,home: ChatApp(),));
}class ChatApp extends StatefulWidget {@override_ChatAppState createState() => _ChatAppState();
}class _ChatAppState extends State<ChatApp> {//for the rest of the tutorial I'll need to import a set of images' Url for the avatar//this is my images listList<String> _avatarUrl = ["https://images.unsplash.com/photo-1573890990305-0ab6a7195ab6?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=634&q=80","https://images.unsplash.com/photo-1463453091185-61582044d556?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80","https://images.unsplash.com/photo-1545130368-4c55e2418062?ixlib=rb-1.2.1&auto=format&fit=crop&w=926&q=80","https://images.unsplash.com/photo-1438761681033-6461ffad8d80?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80","https://images.unsplash.com/photo-1470441623172-c47235e287ee?ixlib=rb-1.2.1&auto=format&fit=crop&w=1052&q=80","https://images.unsplash.com/photo-1458662236860-b721a6735660?ixlib=rb-1.2.1&auto=format&fit=crop&w=1050&q=80","https://images.unsplash.com/photo-1530268729831-4b0b9e170218?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80","https://images.unsplash.com/photo-1534308143481-c55f00be8bd7?ixlib=rb-1.2.1&auto=format&fit=crop&w=1188&q=80","https://images.unsplash.com/photo-1525879000488-bff3b1c387cf?ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80","https://images.unsplash.com/photo-1535201344891-231e85e83c8a?ixlib=rb-1.2.1&auto=format&fit=crop&w=1050&q=80"];//Avatar widgetWidget avatarWidget(String urlImg, double radius) {return Container(width: radius,height: radius,decoration: BoxDecoration(shape: BoxShape.circle,image: DecorationImage(fit: BoxFit.cover,alignment: Alignment.topCenter,image: NetworkImage(urlImg),)),);}//StoryButton widgetWidget storyButton(String urlImg, double radius) {return InkWell(onTap: () {},child: Padding(padding: const EdgeInsets.symmetric(horizontal: 8.0),child: Container(width: radius,height: radius,decoration: BoxDecoration(shape: BoxShape.circle,image: DecorationImage(fit: BoxFit.cover,alignment: Alignment.topCenter,image: NetworkImage(urlImg),)),),),);}//List items widgetWidget listItem(String urlImg, String userName, String, message, String hour) {return InkWell(onTap: () {},child: Padding(padding: EdgeInsets.symmetric(vertical: 8.0, horizontal: 4.0),child: Container(child: Row(children: [avatarWidget(urlImg, 60.0),SizedBox(width: 10.0,),Expanded(child: Column(mainAxisAlignment: MainAxisAlignment.start,crossAxisAlignment: CrossAxisAlignment.start,children: [Text(userName,style: TextStyle(color: Colors.white,fontSize: 20.0,fontWeight: FontWeight.bold,),),Text(message,style: TextStyle(color: Colors.white,fontSize: 16.0,fontWeight: FontWeight.w300,),),],),),Text(hour,style: TextStyle(color: Colors.grey[50],),)],),),),);}@overrideWidget build(BuildContext context) {return Scaffold(backgroundColor: Colors.black,body: Container(child: Padding(padding: const EdgeInsets.symmetric(horizontal: 15.0, vertical: 35.0),child: Column(children: [//First let's create our menu barRow(children: [// for the first par i'll need to create a custom widget for my avatar buttonavatarWidget(_avatarUrl[0], 50.0),SizedBox(width: 10.0,),Expanded(child: Text("Messages",style: TextStyle(color: Colors.white,fontSize: 20.0,fontWeight: FontWeight.w700,),),),MaterialButton(onPressed: () {},elevation: 0.0,padding: EdgeInsets.all(8.0),color: Colors.blue,shape: CircleBorder(),child: Icon(Icons.edit, color: Colors.white),)],),//Now let's create the search barSizedBox(height: 20.0,),TextField(cursorColor: Colors.white,style: TextStyle(color: Colors.white),decoration: InputDecoration(prefixIcon: Icon(Icons.search, color: Colors.white),hintText: "Search",contentPadding: EdgeInsets.only(left: 34.0),filled: true,fillColor: Colors.grey[800],border: OutlineInputBorder(borderRadius: BorderRadius.circular(50.0),borderSide: BorderSide.none,)),),SizedBox(height: 20.0,),//Now it's time to create our list view for storysContainer(height: 60.0,width: double.infinity,child: ListView(scrollDirection: Axis.horizontal,children: [//let's now create our story widget, but before let's add the add buttonMaterialButton(onPressed: () {},elevation: 0.0,padding: EdgeInsets.all(8.0),color: Colors.grey[800],shape: CircleBorder(),child: Icon(Icons.add, color: Colors.grey[300]),),//Now let's create our storybutton widgetstoryButton(_avatarUrl[1], 60.0),storyButton(_avatarUrl[2], 60.0),storyButton(_avatarUrl[3], 60.0),storyButton(_avatarUrl[4], 60.0),],),),SizedBox(height: 10.0,),//Now we will build the chat feed listviewExpanded(child: ListView(children: [//first let's create our list items widgetlistItem(_avatarUrl[2], "David ro", String, "Wassup", "9:53PM"),listItem(_avatarUrl[3], "kasidie", String,"We are waiting for you", "8:33PM"),listItem(_avatarUrl[4], "Lynda", String,"Hey can you help me", "6:54AM"),listItem(_avatarUrl[5], "Suizie Q", String, "hank you","Yesterday"),listItem(_avatarUrl[7], "Joseph", String, "Hey wassup","Yesterday"),listItem(_avatarUrl[8], "Jonathan", String, "okey","Mon, 8:50AM"),//and now all what you have to do is to duplicate that line to have a real chat feed],),)],),),),//Now i'm going to create the button menu barbottomNavigationBar: BottomNavigationBar(backgroundColor: Colors.black,unselectedItemColor: Colors.white,selectedItemColor: Colors.blue,items: [BottomNavigationBarItem(icon: Icon(Icons.message),title: Text("Chat"),),BottomNavigationBarItem(icon: Icon(Icons.people),title: Text("Friend Requests"),),],),);}
}

有时,在获取与您的目标区域相关的相关新信息时,很少有这样的博客会变得非常有用。当我发现这个博客并感谢传递到我的数据库的信息时。

Flutter 构建一个完整的聊天应用程序相关推荐

  1. 学习使用React和Electron一次构建自己的桌面聊天应用程序

    by Alex Booker 通过亚历克斯布克 学习使用React和Electron一次构建自己的桌面聊天应用程序 (Learn to build your own desktop chat app ...

  2. 机器学习入门系列(2)--如何构建一个完整的机器学习项目(一)

    上一篇机器学习入门系列(1)–机器学习概览简单介绍了机器学习的一些基本概念,包括定义.优缺点.机器学习任务的划分等等. 接下来计划通过几篇文章来介绍下,一个完整的机器学习项目的实现步骤会分为几步,最后 ...

  3. 通过python 构建一个简单的聊天服务器

    构建一个 Python 聊天服务器 一个简单的聊天服务器 现在您已经了解了 Python 中基本的网络 API:接下来可以在一个简单的应用程序中应用这些知识了.在本节中,将构建一个简单的聊天服务器.使 ...

  4. myos1 大学生利用C++构建一个完整的操作系统打印helloworld

    myos1 大学生利用C++构建一个完整的操作系统打印helloworld myos2 大学生利用C++构建一个完整的操作系统之响应键盘中断 myos3 大学生利用C++构建一个完整的操作系统之代码重 ...

  5. 用Flutter构建一个 视频通话联系人管理应用

    用Flutter构建一个 视频 / 通话 / 联系人管理 应用 这是编程务实的第三个实验, 要完成一个简单的拨号器.在此需求基础上,我用Flutter添加了一些全新的功能,包括视频通话,观众视角通话, ...

  6. 一个完整的Installshield安装程序实例—艾泽拉斯之海洋女神出品(三) --高级设置一...

    一个完整的Installshield安装程序实例-艾泽拉斯之海洋女神出品(三) --高级设置一 原文:一个完整的Installshield安装程序实例-艾泽拉斯之海洋女神出品(三) --高级设置一 上 ...

  7. python软件代码示例-用Python写一个模拟qq聊天小程序的代码实例

    Python 超简单的聊天程序 客户端: import socket, sys host = '10.248.27.23' # host = raw_input("Plz imput des ...

  8. java 程序输出 赵_编写一个完整的JAVA的程序

    编写一个完整的JAVA的程序 关注:84  答案:1  mip版 解决时间 2021-02-05 08:43 提问者妳螚鬧俄螚笑 2021-02-05 02:59 1,接口Person Show()方 ...

  9. 如何构建一个简单的语音识别应用程序

    "In this 10-year time frame, I believe that we'll not only be using the keyboard and the mouse ...

最新文章

  1. Xcode 中关于#的小知识
  2. Java 洛谷 P1482 Cantor表(升级版)
  3. 照片边框 app android,Screener App-一手搞定将手机截图加上外框
  4. SpringBoot 整合 RabbitMQ 实践
  5. java 泛型 `<E extends Enum<E>>`
  6. PL/SQL(一)简介
  7. js右下角广告[兼容]
  8. 通过矩阵操作实现点的2D线性变换(几何变换、仿射变换)
  9. win10 串口驱动下载链接
  10. Typora无法打开提示安装新版本解决办法
  11. 局域网助手(LanHelper) 1.96 注册码
  12. 服务器上需要高性能显卡吗,英特尔要做独立显卡 只因服务器市场太重要
  13. Java8 新特性并发篇(一) | 线程与执行器
  14. Titan XP值不值?一文教你如何挑选深度学习GPU
  15. 航空器滑行时间预测研究(一)---定义及影响因素
  16. 论文复审意见及实验规划
  17. JWT详细讲解(保姆级教程)
  18. grant with admin option and grant with grant option
  19. c++ crow入门填坑坑
  20. flink sql 指南

热门文章

  1. Oracle清除缓存的命令,Oracle的get命令
  2. cmd52命令发送 mmc_Linux SD/MMC/SDIO驱动分析(新)
  3. setcellvalue 格式_POI对EXCEL的操作【重点:如何设置CELL格式为文本格式】
  4. 的it生活_IT圈生活图鉴篇三丨下班后的突变画风
  5. python获取数组中大于某一阈值的那些索引值_使用Python+OpenCV进行实时车道检测...
  6. 计算机对英语口语考试成绩,英语口语考试面对“电脑考官” 有何临场技巧
  7. python画五角星填充不同颜色_Python绘制分形树(一)
  8. 1、LeetCode784 字母大小写全排列
  9. evaluate函数使用无效_使用Keras和Pytorch处理RNN变长序列输入的方法总结
  10. virsh 关机_KVM virsh常用命令篇