diff --git a/lib/api/apis.dart b/lib/api/apis.dart index 307c351f..c71862bd 100644 --- a/lib/api/apis.dart +++ b/lib/api/apis.dart @@ -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); } \ No newline at end of file diff --git a/lib/pages/user_home_page/header/index.dart b/lib/pages/user_home_page/header/index.dart index 51dc0131..bedfcfe9 100644 --- a/lib/pages/user_home_page/header/index.dart +++ b/lib/pages/user_home_page/header/index.dart @@ -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; @@ -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, - ) - ], - ), - ); - } diff --git a/lib/pages/user_home_page/header/vip_header.dart b/lib/pages/user_home_page/header/vip_header.dart new file mode 100644 index 00000000..ade20345 --- /dev/null +++ b/lib/pages/user_home_page/header/vip_header.dart @@ -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; + } + } + } +} diff --git a/lib/pages/user_home_page/white/index.dart b/lib/pages/user_home_page/white/index.dart index 2582a993..88b106db 100644 --- a/lib/pages/user_home_page/white/index.dart +++ b/lib/pages/user_home_page/white/index.dart @@ -21,7 +21,6 @@ class WhiteIndex extends StatefulWidget { } class WhiteIndexState extends State { - late final MySpecialTextSpanBuilder _mySpecialTextSpanBuilder = MySpecialTextSpanBuilder(context: context); final TextEditingController _textEditingController = TextEditingController(); final GlobalKey _key = GlobalKey(); diff --git a/lib/provider/riverpod/user_riverpod.dart b/lib/provider/riverpod/user_riverpod.dart index 2d2a3afd..22c02288 100644 --- a/lib/provider/riverpod/user_riverpod.dart +++ b/lib/provider/riverpod/user_riverpod.dart @@ -51,4 +51,10 @@ class UserModel extends StateNotifier implements LoginBase{ state = state.copyWith(user: null); GetIt.instance.get().token = null; } + + + //更新用户会员状态 + void openVip() { + state = state.copyWith(user: state.user?.copyWith(vip: Vip.vip)); + } } diff --git a/lib/util/input_utils.dart b/lib/util/input_utils.dart index 6536ecfd..7b7bbf27 100644 --- a/lib/util/input_utils.dart +++ b/lib/util/input_utils.dart @@ -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._(); @@ -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; @@ -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; } diff --git a/pubspec.lock b/pubspec.lock index 1baf635d..b52278af 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: @@ -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: @@ -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: diff --git a/pubspec.yaml b/pubspec.yaml index 5cde4d8b..ae1e3cd0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: