Flutter 构建一个完整的聊天应用程序

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 {

//for the rest of the tutorial I’ll need to import a set of images’ Url for the avatar

//this is my images list

List _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 widget

Widget 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 widget

Widget 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 widget

Widget 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],

),

)

],

),

),

),

);

}

@override

Widget 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 bar

Row(

children: [

// for the first par i’ll need to create a custom widget for my avatar button

avatarWidget(_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,

尾声

对于很多初中级Android工程师而言,想要提升技能,往往是自己摸索成长,不成体系的学习效果低效漫长且无助。 整理的这些架构技术希望对Android开发的朋友们有所参考以及少走弯路,本文的重点是你有没有收获与成长,其余的都不重要,希望读者们能谨记这一点。

最后想要拿高薪实现技术提升薪水得到质的飞跃。最快捷的方式,就是有人可以带着你一起分析,这样学习起来最为高效,所以为了大家能够顺利进阶中高级、架构师,我特地为大家准备了一套高手学习的源码和框架视频等精品Android架构师教程,保证你学了以后保证薪资上升一个台阶。

  • 思维脑图
  • 性能优化学习笔记


  • 性能优化视频

    当你有了学习线路,学习哪些内容,也知道以后的路怎么走了,理论看多了总要实践的。

.(img-LW21cLNj-1720087297533)]

  • 性能优化学习笔记
    [外链图片转存中…(img-HGwrGAmQ-1720087297533)]
    [外链图片转存中…(img-3HvywGvV-1720087297534)]

[外链图片转存中…(img-ngVqCHFH-1720087297534)]
[外链图片转存中…(img-fskpSHcN-1720087297535)]

  • 性能优化视频
    [外链图片转存中…(img-ucQn3Dqr-1720087297535)]
    当你有了学习线路,学习哪些内容,也知道以后的路怎么走了,理论看多了总要实践的。
  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值