Commit a117a5a3d6f709c2edfa9f9fbe1ab34597309eec
1 parent
478f2c8c
feat:更新代码
Showing
10 changed files
with
95 additions
and
13 deletions
lib/app/app.dart
| @@ -2,8 +2,6 @@ import 'package:flutter/material.dart'; | @@ -2,8 +2,6 @@ import 'package:flutter/material.dart'; | ||
| 2 | import 'package:flutter_bloc/flutter_bloc.dart'; | 2 | import 'package:flutter_bloc/flutter_bloc.dart'; |
| 3 | import 'package:flutter_easyloading/flutter_easyloading.dart'; | 3 | import 'package:flutter_easyloading/flutter_easyloading.dart'; |
| 4 | import 'package:flutter_screenutil/flutter_screenutil.dart'; | 4 | import 'package:flutter_screenutil/flutter_screenutil.dart'; |
| 5 | -import 'package:wow_english/app/transition_page.dart'; | ||
| 6 | -import 'package:wow_english/login/login_page.dart'; | ||
| 7 | import 'package:wow_english/route/route.dart'; | 5 | import 'package:wow_english/route/route.dart'; |
| 8 | import 'package:wow_english/tab/blocs/tab_bloc.dart'; | 6 | import 'package:wow_english/tab/blocs/tab_bloc.dart'; |
| 9 | 7 |
lib/app/transition_page.dart renamed to lib/app/splash_page.dart
| 1 | +import 'package:flutter/foundation.dart'; | ||
| 1 | import 'package:flutter/material.dart'; | 2 | import 'package:flutter/material.dart'; |
| 3 | +import 'package:wow_english/network/basic_configuration.dart'; | ||
| 2 | import 'package:wow_english/route/route.dart'; | 4 | import 'package:wow_english/route/route.dart'; |
| 3 | import 'package:wow_english/widgets/we_app_bar.dart'; | 5 | import 'package:wow_english/widgets/we_app_bar.dart'; |
| 4 | 6 | ||
| 5 | -class TransitionPage extends StatelessWidget { | ||
| 6 | - const TransitionPage({super.key}); | 7 | +class SplashPage extends StatelessWidget { |
| 8 | + const SplashPage({super.key}); | ||
| 7 | 9 | ||
| 8 | @override | 10 | @override |
| 9 | Widget build(BuildContext context) { | 11 | Widget build(BuildContext context) { |
| @@ -31,7 +33,11 @@ class _TransitionViewState extends State<TransitionView> { | @@ -31,7 +33,11 @@ class _TransitionViewState extends State<TransitionView> { | ||
| 31 | body: Center( | 33 | body: Center( |
| 32 | child: GestureDetector( | 34 | child: GestureDetector( |
| 33 | onTap: (){ | 35 | onTap: (){ |
| 34 | - Navigator.of(context).pushNamed(AppRouteName.login,arguments: {'title':'登陆'}); | 36 | + if(BasicConfigurationManager().sessionId!.isNotEmpty) { |
| 37 | + Navigator.of(context).pushNamedAndRemoveUntil(AppRouteName.tab, (route) => false); | ||
| 38 | + } else { | ||
| 39 | + Navigator.of(context).pushNamed(AppRouteName.login,arguments: {'title':'登陆'}); | ||
| 40 | + } | ||
| 35 | }, | 41 | }, |
| 36 | child: const Text('登陆'), | 42 | child: const Text('登陆'), |
| 37 | ), | 43 | ), |
lib/login/login_page.dart
| @@ -13,7 +13,6 @@ class LoginPage extends StatelessWidget { | @@ -13,7 +13,6 @@ class LoginPage extends StatelessWidget { | ||
| 13 | 13 | ||
| 14 | @override | 14 | @override |
| 15 | Widget build(BuildContext context) { | 15 | Widget build(BuildContext context) { |
| 16 | - // TODO: implement build | ||
| 17 | return BlocProvider( | 16 | return BlocProvider( |
| 18 | create: (context) => LoginBloc(), | 17 | create: (context) => LoginBloc(), |
| 19 | child: _buildLoginViewWidget(), | 18 | child: _buildLoginViewWidget(), |
| @@ -25,7 +24,6 @@ class LoginPage extends StatelessWidget { | @@ -25,7 +24,6 @@ class LoginPage extends StatelessWidget { | ||
| 25 | final bloc = BlocProvider.of<LoginBloc>(context); | 24 | final bloc = BlocProvider.of<LoginBloc>(context); |
| 26 | return Scaffold( | 25 | return Scaffold( |
| 27 | appBar: WEAppBar( | 26 | appBar: WEAppBar( |
| 28 | - backgroundColor: Theme.of(context).colorScheme.inversePrimary, | ||
| 29 | titleText: title??'', | 27 | titleText: title??'', |
| 30 | ), | 28 | ), |
| 31 | body: Center( | 29 | body: Center( |
lib/modes/response_model.dart
0 → 100644
| 1 | +import 'package:json_annotation/json_annotation.dart'; | ||
| 2 | + | ||
| 3 | +part 'response_model.g.dart'; | ||
| 4 | + | ||
| 5 | +@JsonSerializable() | ||
| 6 | +class ResponseModel { | ||
| 7 | + int? code; | ||
| 8 | + dynamic data; | ||
| 9 | + String? msg; | ||
| 10 | + | ||
| 11 | + ResponseModel(this.code,this.data,this.msg); | ||
| 12 | + | ||
| 13 | + factory ResponseModel.fromJson(Map<String, dynamic> json) => _$ResponseModelFromJson(json); | ||
| 14 | + | ||
| 15 | + Map<String, dynamic> toJson() => _$ResponseModelToJson(this); | ||
| 16 | +} |
lib/modes/response_model.g.dart
0 → 100644
| 1 | +// GENERATED CODE - DO NOT MODIFY BY HAND | ||
| 2 | + | ||
| 3 | +part of 'response_model.dart'; | ||
| 4 | + | ||
| 5 | +// ************************************************************************** | ||
| 6 | +// JsonSerializableGenerator | ||
| 7 | +// ************************************************************************** | ||
| 8 | + | ||
| 9 | +ResponseModel _$ResponseModelFromJson(Map<String, dynamic> json) => | ||
| 10 | + ResponseModel( | ||
| 11 | + json['code'] as int?, | ||
| 12 | + json['data'], | ||
| 13 | + json['msg'] as String?, | ||
| 14 | + ); | ||
| 15 | + | ||
| 16 | +Map<String, dynamic> _$ResponseModelToJson(ResponseModel instance) => | ||
| 17 | + <String, dynamic>{ | ||
| 18 | + 'code': instance.code, | ||
| 19 | + 'data': instance.data, | ||
| 20 | + 'msg': instance.msg, | ||
| 21 | + }; |
lib/network/api.dart
lib/network/basic_configuration.dart
0 → 100644
| 1 | +enum DevelopEvent { | ||
| 2 | + ///开发环境 | ||
| 3 | + dev, | ||
| 4 | + ///测试环境 | ||
| 5 | + test, | ||
| 6 | + ///正式环境 | ||
| 7 | + formal | ||
| 8 | +} | ||
| 9 | + | ||
| 10 | +class BasicConfigurationManager { | ||
| 11 | + factory BasicConfigurationManager() => _getInstance(); | ||
| 12 | + | ||
| 13 | + static BasicConfigurationManager? _instance; | ||
| 14 | + | ||
| 15 | + //服务器地址 | ||
| 16 | + String? baseUrl; | ||
| 17 | + //SessionId | ||
| 18 | + String? sessionId; | ||
| 19 | + | ||
| 20 | + BasicConfigurationManager._internal(){ | ||
| 21 | + DevelopEvent developType = DevelopEvent.dev; | ||
| 22 | + if (developType == DevelopEvent.test) { | ||
| 23 | + baseUrl = 'http://wow-app.dev.kouyuxingqiu.com'; | ||
| 24 | + } else if(developType == DevelopEvent.dev) { | ||
| 25 | + baseUrl = 'http://wow-app.dev.kouyuxingqiu.com'; | ||
| 26 | + } else { | ||
| 27 | + baseUrl = 'http://wow-app.dev.kouyuxingqiu.com'; | ||
| 28 | + } | ||
| 29 | + sessionId = ''; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + static BasicConfigurationManager _getInstance() { | ||
| 33 | + _instance ??= BasicConfigurationManager._internal(); | ||
| 34 | + return _instance!; | ||
| 35 | + } | ||
| 36 | +} | ||
| 0 | \ No newline at end of file | 37 | \ No newline at end of file |
lib/network/network_manager.dart
| @@ -3,6 +3,7 @@ import 'dart:io'; | @@ -3,6 +3,7 @@ import 'dart:io'; | ||
| 3 | import 'package:dio/dio.dart'; | 3 | import 'package:dio/dio.dart'; |
| 4 | import 'package:flutter/foundation.dart'; | 4 | import 'package:flutter/foundation.dart'; |
| 5 | import 'package:flutter_easyloading/flutter_easyloading.dart'; | 5 | import 'package:flutter_easyloading/flutter_easyloading.dart'; |
| 6 | +import 'package:wow_english/network/basic_configuration.dart'; | ||
| 6 | 7 | ||
| 7 | enum HttpMethod { | 8 | enum HttpMethod { |
| 8 | get, | 9 | get, |
| @@ -24,9 +25,10 @@ class DioUtil { | @@ -24,9 +25,10 @@ class DioUtil { | ||
| 24 | 25 | ||
| 25 | static BaseOptions getDefOptions() { | 26 | static BaseOptions getDefOptions() { |
| 26 | final BaseOptions options = BaseOptions(); | 27 | final BaseOptions options = BaseOptions(); |
| 27 | - options.baseUrl = ''; | 28 | + options.baseUrl = BasicConfigurationManager().baseUrl??''; |
| 28 | options.connectTimeout = const Duration(milliseconds: 1000); | 29 | options.connectTimeout = const Duration(milliseconds: 1000); |
| 29 | options.receiveTimeout = const Duration(milliseconds: 1000); | 30 | options.receiveTimeout = const Duration(milliseconds: 1000); |
| 31 | + options.headers['content-type'] = 'application/x-www-form-urlencoded'; | ||
| 30 | return options; | 32 | return options; |
| 31 | } | 33 | } |
| 32 | 34 | ||
| @@ -41,12 +43,17 @@ class DioUtil { | @@ -41,12 +43,17 @@ class DioUtil { | ||
| 41 | required Function errorCallBack, | 43 | required Function errorCallBack, |
| 42 | }) async{ | 44 | }) async{ |
| 43 | try { | 45 | try { |
| 46 | + Map<String, dynamic> headers = <String, dynamic>{}; | ||
| 47 | + | ||
| 48 | + if (method == HttpMethod.post) { | ||
| 49 | + headers['content-type'] = 'application/x-www-form-urlencoded'; | ||
| 50 | + } | ||
| 44 | Response<dynamic> response; | 51 | Response<dynamic> response; |
| 45 | response = await _dio.request( | 52 | response = await _dio.request( |
| 46 | path, | 53 | path, |
| 47 | data: data??{}, | 54 | data: data??{}, |
| 48 | queryParameters: queryParameters, | 55 | queryParameters: queryParameters, |
| 49 | - options: Options(method: method.name), | 56 | + options: Options(method: method.name,headers: headers), |
| 50 | onSendProgress: onSendProgress, | 57 | onSendProgress: onSendProgress, |
| 51 | onReceiveProgress: onReceiveProgress); | 58 | onReceiveProgress: onReceiveProgress); |
| 52 | if (response.statusCode == HttpStatus.ok || | 59 | if (response.statusCode == HttpStatus.ok || |
lib/route/route.dart
| 1 | import 'package:flutter/cupertino.dart'; | 1 | import 'package:flutter/cupertino.dart'; |
| 2 | import 'package:flutter/material.dart'; | 2 | import 'package:flutter/material.dart'; |
| 3 | -import 'package:wow_english/app/transition_page.dart'; | 3 | +import 'package:wow_english/app/splash_page.dart'; |
| 4 | import 'package:wow_english/login/login_page.dart'; | 4 | import 'package:wow_english/login/login_page.dart'; |
| 5 | import 'package:wow_english/tab/tab_page.dart'; | 5 | import 'package:wow_english/tab/tab_page.dart'; |
| 6 | 6 | ||
| @@ -21,7 +21,7 @@ class AppRouter { | @@ -21,7 +21,7 @@ class AppRouter { | ||
| 21 | case AppRouteName.splash: | 21 | case AppRouteName.splash: |
| 22 | return PageRouteBuilder( | 22 | return PageRouteBuilder( |
| 23 | opaque: false, | 23 | opaque: false, |
| 24 | - pageBuilder: (_,__,___) => const TransitionPage(), | 24 | + pageBuilder: (_,__,___) => const SplashPage(), |
| 25 | transitionDuration: Duration.zero, | 25 | transitionDuration: Duration.zero, |
| 26 | transitionsBuilder: (_, __, ___, child) => child); | 26 | transitionsBuilder: (_, __, ___, child) => child); |
| 27 | case AppRouteName.login: | 27 | case AppRouteName.login: |
lib/widgets/we_app_bar.dart
| @@ -19,7 +19,7 @@ class WEAppBar extends StatelessWidget implements PreferredSizeWidget { | @@ -19,7 +19,7 @@ class WEAppBar extends StatelessWidget implements PreferredSizeWidget { | ||
| 19 | return AppBar( | 19 | return AppBar( |
| 20 | centerTitle: centerTitle, | 20 | centerTitle: centerTitle, |
| 21 | title: Text(titleText??''), | 21 | title: Text(titleText??''), |
| 22 | - backgroundColor: backgroundColor, | 22 | + backgroundColor: backgroundColor??Theme.of(context).colorScheme.inversePrimary, |
| 23 | ); | 23 | ); |
| 24 | } | 24 | } |
| 25 | 25 |