Skip to content

Commit

Permalink
bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
mdddj committed May 22, 2023
1 parent 4f9c5bc commit 5cd1999
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 67 deletions.
5 changes: 5 additions & 0 deletions lib/api/apis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,10 @@ class MyApiWithLogin extends MyAppCoreApi {
///美团领券
class MeituanCoupon extends MyAppCoreApi {
MeituanCoupon():super('/api/zhe/mt/tg');
}


///开通会员接口
class MyOpenVipApi extends MyAppCoreApi {
MyOpenVipApi():super("/api/open-vip",httpMethod: HttpMethod.post);
}
63 changes: 2 additions & 61 deletions lib/pages/user_home_page/header/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import '../../../constant/style.dart';
import '../../../provider/riverpod/model/my_user.dart';
import '../../../provider/riverpod/user_riverpod.dart';
import '../../../util/navigator_util.dart';
import 'vip_header.dart';

const kAvatarHeight = 58.0;

Expand All @@ -35,73 +36,13 @@ class HeaderIndex extends ConsumerWidget {
const SizedBox(
height: 44,
),
_renderVip()
const VipHeader()
],
),
),
);
}

// 开通会员
Widget _renderVip() {
return Container(
decoration: BoxDecoration(
color: Colors.orange.shade200,
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(8), topRight: Radius.circular(8))),
child: Row(
children: [
SizedBox(
width: 80,
height: 60,
child: Center(
child: Image.asset(
'assets/images/vip.png',
width: 38,
height: 38,
),
),
),
const Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'会员可享有多项特权',
style: TextStyle(
color: Colors.black,
fontSize: 18,
fontWeight: FontWeight.bold),
),
Text('未开通特权', style: TextStyle(color: Colors.black))
]),
),
Center(
child: SizedBox(
width: 100,
height: 38,
child: ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.black),
shape: MaterialStateProperty.all(RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100)))),
child: const Text(
'免费激活',
style: TextStyle(color: Colors.yellow),
),
onPressed: () {
// 激活会员
},
),
),
),
const SizedBox(
width: 12,
)
],
),
);
}



Expand Down
114 changes: 114 additions & 0 deletions lib/pages/user_home_page/header/vip_header.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import 'package:dd_js_util/dd_js_util.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

import '../../../api/apis.dart';
import '../../../common/api_ext.dart';
import '../../../index.dart';
import '../../../provider/riverpod/model/my_user.dart';

//开通会员标识
class VipHeader extends ConsumerWidget {
const VipHeader({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final vip = ref.user?.vip ?? Vip.none;

return Container(
decoration: BoxDecoration(
color: Colors.orange.shade200,
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(8), topRight: Radius.circular(8))),
child: Row(
children: [
SizedBox(
width: 80,
height: 60,
child: Center(
child: Image.asset(
'assets/images/vip.png',
width: 38,
height: 38,
),
),
),
Expanded(
child:
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
const Text(
'会员可享有多项特权',
style: TextStyle(
color: Colors.black,
fontSize: 18,
fontWeight: FontWeight.bold),
),
Text(_isVip(vip) ? '您已经是 VIP 会员' : '未开通特权', style: const TextStyle(color: Colors.black))
]),
),
Center(
child: SizedBox(
width: 100,
height: 38,
child: ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.black),
shape: MaterialStateProperty.all(RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100)))),
onPressed:_isVip(vip)? null : ()=>_openVip(ref),
child: Text(
_buttonText(vip),
style: const TextStyle(color: Colors.yellow),
),
),
),
),
const SizedBox(
width: 12,
)
],
),
);
}




//开通会员
void _openVip(WidgetRef ref) {
MyOpenVipApi().request(const R()).then((value) {
value.simpleToast(ifOk: (){
ref.read(userRiverpod.notifier).openVip();
});
});
}

String _buttonText(Vip vip) {
switch(vip){
case Vip.none: {
return "开通会员";
}
case Vip.vip: {
return "已开通";
}
case Vip.superVip: {
return "已开通";
}
case Vip.specialVip:{
return "已开通";
}
}
}


bool _isVip(Vip vip) {
switch(vip){
case Vip.none:{
return false;
}
default:{
return true;
}
}
}
}
1 change: 0 additions & 1 deletion lib/pages/user_home_page/white/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class WhiteIndex extends StatefulWidget {
}

class WhiteIndexState extends State<WhiteIndex> {
late final MySpecialTextSpanBuilder _mySpecialTextSpanBuilder = MySpecialTextSpanBuilder(context: context);
final TextEditingController _textEditingController = TextEditingController();
final GlobalKey _key = GlobalKey();

Expand Down
6 changes: 6 additions & 0 deletions lib/provider/riverpod/user_riverpod.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,10 @@ class UserModel extends StateNotifier<UserDetailModal> implements LoginBase{
state = state.copyWith(user: null);
GetIt.instance.get<UserApi>().token = null;
}


//更新用户会员状态
void openVip() {
state = state.copyWith(user: state.user?.copyWith(vip: Vip.vip));
}
}
5 changes: 0 additions & 5 deletions lib/util/input_utils.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import '../pages/user_home_page/white/my_special_text_span_builder.dart';

class InputUtils {
const InputUtils._();
Expand Down Expand Up @@ -75,7 +74,6 @@ class InputUtils {
return;
}
// Delete the previous character.
final myValue = controller.value;
final previousCodeUnit = text.codeUnitAt(textSelection.start - 1);
final offset = _isUtf16Surrogate(previousCodeUnit) ? 2 : 1;
final newStart = textSelection.start - offset;
Expand All @@ -85,9 +83,6 @@ class InputUtils {
text: newText,
selection: TextSelection.collapsed(offset: newStart),
);
final oldTextSpan = MySpecialTextSpanBuilder(context: context).build(
myValue.text,
);
// value = handleSpecialTextSpanDelete(value, myValue, oldTextSpan, null);
controller.value = value;
}
Expand Down
32 changes: 32 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "5.13.0"
analyzer_plugin:
dependency: transitive
description:
name: analyzer_plugin
sha256: c1d5f167683de03d5ab6c3b53fc9aeefc5d59476e7810ba7bbddff50c6f4392d
url: "https://pub.dev"
source: hosted
version: "0.11.2"
animated_text_kit:
dependency: "direct main"
description:
Expand Down Expand Up @@ -201,6 +209,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.2"
ci:
dependency: transitive
description:
name: ci
sha256: "145d095ce05cddac4d797a158bc4cf3b6016d1fe63d8c3d2fbd7212590adca13"
url: "https://pub.dev"
source: hosted
version: "0.1.0"
cli_util:
dependency: transitive
description:
name: cli_util
sha256: b8db3080e59b2503ca9e7922c3df2072cf13992354d5e944074ffa836fba43b7
url: "https://pub.dev"
source: hosted
version: "0.4.0"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -273,6 +297,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.5"
custom_lint:
dependency: "direct dev"
description:
name: custom_lint
sha256: "3ce36c04d30c60cde295588c6185b3f9800e6c18f6670a7ffdb3d5eab39bb942"
url: "https://pub.dev"
source: hosted
version: "0.4.0"
dart_style:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ dev_dependencies:
analyzer: ^5.13.0
freezed: ^2.3.4
json_serializable: ^6.7.0
custom_lint: ^0.4.0


flutter:
Expand Down

0 comments on commit 5cd1999

Please sign in to comment.