exchange_lesson_page.dart
5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:wow_english/common/extension/string_extension.dart';
import 'package:wow_english/common/widgets/textfield_customer_widget.dart';
import 'package:wow_english/pages/shop/exchane/widegts/exchange_result_dialog.dart';
import 'package:wow_english/route/route.dart';
import '../../../common/widgets/we_app_bar.dart';
import 'bloc/exchange_lesson_bloc.dart';
class ExchangeLessonPage extends StatelessWidget {
  const ExchangeLessonPage({super.key});
  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (context) => ExchangeLessonBloc(),
      child: _ExchangeLessonPage(),
    );
  }
}
class _ExchangeLessonPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return BlocListener<ExchangeLessonBloc, ExchangeLessonState>(
      listener: (context, state) {
        if (state is CheckCodeResultState) {
          showDialog<ExChangeResultDialog>(
              context: context,
              barrierDismissible: !state.result,
              builder: (context) {
                return ExChangeResultDialog(
                    resultType: state.result,
                    onTap: () {
                      popPage();
                    });
              });
        }
      },
      child: _exchangeLessonPageView(),
    );
  }
  Widget _exchangeLessonPageView() =>
      BlocBuilder<ExchangeLessonBloc, ExchangeLessonState>(
          builder: (context, state) {
        final bloc = BlocProvider.of<ExchangeLessonBloc>(context);
        return Scaffold(
            resizeToAvoidBottomInset: false,
            body: Stack(
              children: [
                Container(
                  color: Colors.white,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      10.5.verticalSpace,
                      Padding(
                        padding: EdgeInsets.symmetric(horizontal: 15.w),
                        child: Center(
                          child: Image.asset(
                            'wow_ex_lesson'.assetPng,
                            width: 139.w,
                            height: 81.h,
                          ),
                        ),
                      ),
                      Expanded(
                        child: Padding(
                          padding: EdgeInsets.symmetric(horizontal: 135.w),
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              TextFieldCustomerWidget(
                                height: 55.h,
                                hitText: '请输入兑换码',
                                bgImageName: 'Input_layer_up',
                                textInputType: TextInputType.emailAddress,
                                controller: bloc.codeNumberController,
                                onChangeValue: (String value) {
                                  bloc.add(CodeNumberChangeEvent());
                                },
                              ),
                              21.5.verticalSpace,
                              GestureDetector(
                                onTap: () {
                                  if (bloc.checkCode) {
                                    bloc.add(CheckCodeEvent());
                                  }
                                },
                                child: Container(
                                  decoration: BoxDecoration(
                                    image: DecorationImage(
                                        image: AssetImage(bloc.checkCode
                                            ? 'ex_sure'.assetPng
                                            : 'ex_dis'.assetPng),
                                        fit: BoxFit.fill),
                                  ),
                                  padding: EdgeInsets.symmetric(
                                      horizontal: 27.w, vertical: 14.h),
                                  child: Text(
                                    '兑换',
                                    style: TextStyle(
                                        fontSize: 16.sp, color: Colors.white),
                                  ),
                                ),
                              )
                            ],
                          ),
                        ),
                      ),
                      Image.asset(
                        'bottom_grass'.assetPng,
                      ),
                    ],
                  ),
                ),
                const Positioned(
                  top: 0,
                  left: 0,
                  right: 0,
                  child: WEAppBar(
                    backgroundColor: Colors.transparent,
                  ),
                ),
              ],
            ));
      });
}