login_qr_page.dart 5.95 KB
import 'package:appframe/bloc/login_qr_cubit.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class LoginQrPage extends StatelessWidget {
  const LoginQrPage({super.key});

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
        create: (BuildContext context) => LoginQrCubit(LoginQrState()),
        child: BlocConsumer<LoginQrCubit, LoginQrState>(
          builder: (context, state) {
            var loginQrCubit = context.read<LoginQrCubit>();
            return Scaffold(
              backgroundColor: Colors.white,
              body: SafeArea(
                top: false,
                child: SingleChildScrollView(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    children: [
                      Image.asset(
                        'assets/images/login_v2/banner_2.png',
                        width: MediaQuery.of(context).size.width,
                        fit: BoxFit.fitWidth,
                      ),
                      SizedBox(
                        height: 380,
                        child: _buildQrCode(loginQrCubit, state),
                      ),
                      SizedBox(height: 20),
                      Center(
                        child: Text(
                          '其他方式登录',
                          style: TextStyle(
                            fontSize: 14,
                            color: Color(0xFF999999),
                          ),
                          strutStyle: StrutStyle(height: 16 / 14),
                        ),
                      ),
                      SizedBox(height: 15),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          InkWell(
                            onTap: () {
                              loginQrCubit.goLoginMain();
                            },
                            child: Image.asset(
                              'assets/images/login_v2/wechat_green_icon.png',
                            ),
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
              ),
            );
          },
          listener: (context, state) {},
        ));
  }

  Column? _buildQrCode(LoginQrCubit loginQrCubit, LoginQrState state) {
    if (state.status == 0) {
      // 等待二维码数据
      return Column(
        children: [
          Column(
            children: [
              SizedBox(height: 112),
              Image.asset(
                'assets/images/login_v2/loading.gif',
                width: 72,
                height: 72,
              ),
              SizedBox(height: 24),
              Text(
                '正在生成二维码...',
                style: TextStyle(
                  fontSize: 14,
                  color: Color(0xFF333333),
                ),
                strutStyle: StrutStyle(height: 16 / 14),
              ),
              SizedBox(height: 8),
              Text(
                state.tip,
                style: TextStyle(
                  fontSize: 14,
                  color: Color(0xFF333333),
                ),
                strutStyle: StrutStyle(height: 16 / 14),
              ),
            ],
          ),
        ],
      );
    } else if (state.status == 1) {
      // 等待扫码
      return Column(
        children: [
          Container(
            width: 230,
            height: 230,
            padding: EdgeInsets.all(20),
            decoration: BoxDecoration(
              border: Border.all(
                color: Color(0x29265ECF),
                width: 0.5,
              ),
              borderRadius: BorderRadius.circular(20),
            ),
            child: Image.memory(
              state.image!,
              width: 190,
              height: 190,
            ),
          ),
          SizedBox(height: 12),
          Text(
            state.tip,
            style: TextStyle(
              fontSize: 14,
              color: Color(0xFF333333),
            ),
            strutStyle: StrutStyle(height: 16 / 14),
          ),
        ],
      );
    } else if (state.status == 2) {
      // 已扫码,等待确认
      return Column(
        children: [
          SizedBox(height: 15.5),
          Image.asset(
            "assets/images/login_v2/allowed.png",
            width: 217,
            height: 190,
          ),
          SizedBox(height: 15.5),
          Text(
            "已扫码",
            style: TextStyle(
              fontSize: 16,
              fontWeight: FontWeight.bold,
              fontFamily: '黑体',
              color: Color(0xFF333333),
            ),
            strutStyle: StrutStyle(height: 21 / 16),
          ),
          SizedBox(height: 8),
          Text(
            state.tip,
            style: TextStyle(
              fontSize: 14,
              color: Color(0xFF333333),
            ),
            strutStyle: StrutStyle(height: 16 / 14),
          ),
        ],
      );
    } else if (state.status == 3) {
      // 拒绝
      return Column(
        children: [
          SizedBox(height: 15.5),
          Image.asset(
            "assets/images/login_v2/refused.png",
            width: 217,
            height: 190,
          ),
          SizedBox(height: 15.5),
          Text(
            "拒绝登录",
            style: TextStyle(
              fontSize: 16,
              fontWeight: FontWeight.bold,
              fontFamily: '黑体',
              color: Color(0xFF333333),
            ),
            strutStyle: StrutStyle(height: 21 / 16),
          ),
          SizedBox(height: 8),
          Text(
            state.tip,
            style: TextStyle(
              fontSize: 14,
              color: Color(0xFF333333),
            ),
            strutStyle: StrutStyle(height: 16 / 14),
          ),
        ],
      );
    }
    return null;
  }
}