0 项目说明
基于Flutter的聊天社交应用
提示:适合用于课程设计或毕业设计,工作量达标,源码开放
FYim(flutter-yim)是基于 Flutter 技术开发的一款跨平台聊天社交应用,主要包含 IM(仿微信)、电影(仿豆瓣)、小说(仿书旗小说)、音乐(仿网易云音乐)四大模块。
1 开发环境
$ flutter --version
Flutter 1.5.4-hotfix.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 7a4c33425d (2 weeks ago) • 2019-04-29 11:05:24 -0700
Engine • revision 52c7a1e849
Tools • Dart 2.3.0 (build 2.3.0-dev.0.5 a1668566e5)
Android Studio 3.4
Build #AI-183.5429.30.34.5452501, built on April 10, 2019
JRE: 1.8.0_152-release-1343-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
FlutterBoost 需要修改源码:
BoostFlutterView.java
ViewCompat android.support => androidxBoostFlutterFragment.java
Fragment android.support => androidxBoostFlutterNativeView.java
去掉 detach 的 @Override
3 界面效果图
YIM主模块(仿微信)
Yim电影模块(仿豆瓣)
Yim音乐模块(仿网易云音乐)
4 项目源码
package com.devyy.flutter.yim.account;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.Toast;
import androidx.annotation.Nullable;
import com.devyy.flutter.yim.PageRouter;
import com.devyy.flutter.yim.R;
import com.devyy.flutter.yim.YIMHelper;
import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;
/**
* 用户登录页面
* 环信登录功能
*
* @author zhangyiyang
* @since 2019-03-16
*/
public class LoginActivity extends Activity {
private static final String TAG = "==>LoginActivity";
private EditText usernameEditText;
private EditText passwordEditText;
private boolean progressShow;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 若已经登录
if (YIMHelper.getInstance().isLoggedIn()) {
boolean autoLogin = true;
// 跳转至主页面
PageRouter.openPageByUrl(this, PageRouter.FLUTTER_PAGE_URL);
return;
}
setContentView(R.layout.em_activity_login);
usernameEditText = (EditText) findViewById(R.id.username);
passwordEditText = (EditText) findViewById(R.id.password);
// 如果用户名栏变更,重置密码输入栏
usernameEditText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
passwordEditText.setText(null);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
passwordEditText.setOnEditorActionListener((v, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_DONE
|| ((event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
&& (event.getAction() == KeyEvent.ACTION_DOWN))) {
login(null);
return true;
} else {
return false;
}
});
}
/**
* 登录
*/
public void login(View view) {
String currentUsername = usernameEditText.getText().toString().trim();
String currentPassword = passwordEditText.getText().toString().trim();
if (TextUtils.isEmpty(currentUsername)) {
Toast.makeText(this, "用户名不能为空", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(currentPassword)) {
Toast.makeText(this, "密码不能为空", Toast.LENGTH_SHORT).show();
return;
}
// ProgressDialog
progressShow = true;
final ProgressDialog pd = new ProgressDialog(LoginActivity.this);
pd.setCanceledOnTouchOutside(false);
pd.setOnCancelListener(dialog -> {
Log.d(TAG, "EMClient.getInstance().onCancel");
progressShow = false;
});
pd.setMessage("登陆ing……");
pd.show();
// 保存用户名
YIMHelper.getInstance().setCurrentUserName(currentUsername);
// call login method
Log.d(TAG, "EMClient.getInstance().login");
EMClient.getInstance().login(currentUsername, currentPassword, new EMCallBack() {
@Override
public void onSuccess() {
Log.d(TAG, "登录成功!");
// 加载本地会话和群组
EMClient.getInstance().groupManager().loadAllGroups();
EMClient.getInstance().chatManager().loadAllConversations();
if (!LoginActivity.this.isFinishing() && pd.isShowing()) {
pd.dismiss();
}
// 跳转至主页面
PageRouter.openPageByUrl(LoginActivity.this, PageRouter.FLUTTER_PAGE_URL);
}
@Override
public void onProgress(int progress, String status) {
Log.d(TAG, "登陆中···");
}
@Override
public void onError(final int code, final String message) {
Log.d(TAG, "登录失败: " + code);
if (!progressShow) {
return;
}
runOnUiThread(() -> {
pd.dismiss();
Toast.makeText(getApplicationContext(), "登录失败:" + message,
Toast.LENGTH_SHORT).show();
});
}
});
}
/**
* 注册
*/
public void register(View view) {
startActivityForResult(new Intent(this, RegisterActivity.class), 0);
}
@Override
protected void onResume() {
super.onResume();
}
}