Blame view

lib/login/login_page.dart 2.22 KB
2a29701f   liangchengyou   feat:提交代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  import 'package:flutter/foundation.dart';
  import 'package:flutter/material.dart';
  import 'package:flutter_bloc/flutter_bloc.dart';
  import 'package:wow_english/login/blocs/login_bloc.dart';
  import 'package:wow_english/modes/test_model.dart';
  import 'package:wow_english/route/route.dart';
  import 'package:wow_english/widgets/we_app_bar.dart';
  
  class LoginPage extends StatelessWidget {
    const LoginPage({super.key, this.title});
  
    final String? title;
  
    @override
    Widget build(BuildContext context) {
2a29701f   liangchengyou   feat:提交代码
16
17
18
19
20
21
22
23
24
25
26
      return BlocProvider(
        create: (context) => LoginBloc(),
        child: _buildLoginViewWidget(),
      );
    }
  
    Widget _buildLoginViewWidget() => BlocBuilder<LoginBloc,LoginState> (
      builder: (context, state) {
        final bloc = BlocProvider.of<LoginBloc>(context);
        return Scaffold(
          appBar: WEAppBar(
2a29701f   liangchengyou   feat:提交代码
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
            titleText: title??'',
          ),
          body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                GestureDetector(
                  onTap: () {
                    Navigator.of(context).pushNamedAndRemoveUntil(AppRouteName.tab, (route) => false);
                  },
                  child: const Text(
                      '进入首页'
                  ),
                ),
                Text(
                    bloc.isLogin?'登陆成功':'还未登陆'
                ),
                GestureDetector(
                  onTap: () {
                   TestModel testModel = TestModel(name: 'lcy',age: 31,sex: '男');
                   Map<String,dynamic> jsonMap =  testModel.toJson();
                   if (kDebugMode) {
                     print(jsonMap);
                   }
                   TestModel testModel2 = TestModel.fromJson(jsonMap);
                   if (kDebugMode) {
                     print(testModel2.name);
                   }
                  },
                  child: const Text(
                      '数据转换'
                  ),
                ),
                GestureDetector(
                  onTap: (){
                    bloc.add(RequestLoginEvent());
                  },
                  child: const Text(
                      '发起网络请求'
                  ),
                )
              ],
            ),
          ),
        );
      },
    );
  }