Commit 79d054ab by tanghuan

iOS中未安装微信App时,设置界面不显示"在线客服"

1 parent 5a44fc5c
......@@ -11,21 +11,25 @@ import 'package:shared_preferences/shared_preferences.dart';
class SettingState extends Equatable {
final String h5Version;
final bool wechatInstalled;
const SettingState({
this.h5Version = '',
this.wechatInstalled = false,
});
SettingState copyWith({
String? h5Version,
bool? wechatInstalled,
}) {
return SettingState(
h5Version: h5Version ?? this.h5Version,
wechatInstalled: wechatInstalled ?? this.wechatInstalled,
);
}
@override
List<Object?> get props => [h5Version];
List<Object?> get props => [h5Version, wechatInstalled];
}
class SettingCubit extends Cubit<SettingState> {
......@@ -38,6 +42,7 @@ class SettingCubit extends Cubit<SettingState> {
void _init() {
_readH5ShowVersion();
_checkWechat();
}
void _readH5ShowVersion() {
......@@ -45,6 +50,13 @@ class SettingCubit extends Cubit<SettingState> {
emit(state.copyWith(h5Version: h5Version));
}
// 微信安装检测
void _checkWechat() {
_fluwx.isWeChatInstalled.then((value) {
emit(state.copyWith(wechatInstalled: value));
});
}
/// 跳转客服(微信小程序)
void goCs() {
_fluwx.open(
......
import 'dart:io';
import 'package:appframe/bloc/setting/setting_cubit.dart';
import 'package:appframe/config/constant.dart';
import 'package:appframe/config/env_config.dart';
......@@ -16,6 +18,33 @@ class SettingPage extends StatelessWidget {
builder: (context, state) {
final settingCubit = context.read<SettingCubit>();
var customerService = Platform.isAndroid || state.wechatInstalled
? [
Card(
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 2),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
),
child: Column(
children: [
ListTile(
leading: const Icon(Icons.headset_mic, size: 20),
title: const Text('在线客服', style: TextStyle(fontSize: 14)),
onTap: () {
settingCubit.goCs();
},
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
trailing: const Icon(Icons.arrow_forward_ios, size: 14),
dense: true,
visualDensity: VisualDensity.compact,
),
],
),
),
const SizedBox(height: 8),
]
: [];
return Scaffold(
appBar: AppBar(
title: const Text('设置', style: TextStyle(color: Colors.white, fontSize: 18)),
......@@ -129,28 +158,7 @@ class SettingPage extends StatelessWidget {
),
),
const SizedBox(height: 8),
Card(
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 2),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
),
child: Column(
children: [
ListTile(
leading: const Icon(Icons.headset_mic, size: 20),
title: const Text('在线客服', style: TextStyle(fontSize: 14)),
onTap: () {
settingCubit.goCs();
},
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
trailing: const Icon(Icons.arrow_forward_ios, size: 14),
dense: true,
visualDensity: VisualDensity.compact,
),
],
),
),
const SizedBox(height: 8),
...customerService,
Card(
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 2),
shape: RoundedRectangleBorder(
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!