├── ios
├── Runner
│ ├── Runner-Bridging-Header.h
│ ├── Assets.xcassets
│ │ ├── LaunchImage.imageset
│ │ │ ├── LaunchImage.png
│ │ │ ├── LaunchImage@2x.png
│ │ │ ├── LaunchImage@3x.png
│ │ │ ├── README.md
│ │ │ └── Contents.json
│ │ └── AppIcon.appiconset
│ │ │ ├── Icon-App-20x20@1x.png
│ │ │ ├── Icon-App-20x20@2x.png
│ │ │ ├── Icon-App-20x20@3x.png
│ │ │ ├── Icon-App-29x29@1x.png
│ │ │ ├── Icon-App-29x29@2x.png
│ │ │ ├── Icon-App-29x29@3x.png
│ │ │ ├── Icon-App-40x40@1x.png
│ │ │ ├── Icon-App-40x40@2x.png
│ │ │ ├── Icon-App-40x40@3x.png
│ │ │ ├── Icon-App-60x60@2x.png
│ │ │ ├── Icon-App-60x60@3x.png
│ │ │ ├── Icon-App-76x76@1x.png
│ │ │ ├── Icon-App-76x76@2x.png
│ │ │ ├── Icon-App-1024x1024@1x.png
│ │ │ ├── Icon-App-83.5x83.5@2x.png
│ │ │ └── Contents.json
│ ├── AppDelegate.swift
│ ├── Base.lproj
│ │ ├── Main.storyboard
│ │ └── LaunchScreen.storyboard
│ └── Info.plist
├── Flutter
│ ├── Debug.xcconfig
│ ├── Release.xcconfig
│ └── AppFrameworkInfo.plist
├── Runner.xcodeproj
│ ├── project.xcworkspace
│ │ └── contents.xcworkspacedata
│ ├── xcshareddata
│ │ └── xcschemes
│ │ │ └── Runner.xcscheme
│ └── project.pbxproj
├── Runner.xcworkspace
│ └── contents.xcworkspacedata
├── Podfile.lock
└── Podfile
├── img
├── img_a.png
└── pic_b.png
├── android
├── gradle.properties
├── app
│ ├── src
│ │ ├── main
│ │ │ ├── res
│ │ │ │ ├── mipmap-hdpi
│ │ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-mdpi
│ │ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xhdpi
│ │ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xxhdpi
│ │ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xxxhdpi
│ │ │ │ │ └── ic_launcher.png
│ │ │ │ ├── values
│ │ │ │ │ └── styles.xml
│ │ │ │ └── drawable
│ │ │ │ │ └── launch_background.xml
│ │ │ ├── kotlin
│ │ │ │ └── com
│ │ │ │ │ └── example
│ │ │ │ │ └── flutter_http_utils
│ │ │ │ │ └── MainActivity.kt
│ │ │ └── AndroidManifest.xml
│ │ ├── debug
│ │ │ └── AndroidManifest.xml
│ │ └── profile
│ │ │ └── AndroidManifest.xml
│ └── build.gradle
├── gradle
│ └── wrapper
│ │ └── gradle-wrapper.properties
├── settings.gradle
└── build.gradle
├── .metadata
├── lib
├── http_util
│ ├── base_response.dart
│ ├── request_listener.dart
│ └── my_http_util.dart
├── bloc
│ ├── bloc_provider.dart
│ └── music_bloc.dart
├── bean
│ ├── music.dart
│ └── music.g.dart
└── main.dart
├── test
└── widget_test.dart
├── .gitignore
├── README.md
├── pubspec.yaml
└── pubspec.lock
/ios/Runner/Runner-Bridging-Header.h:
--------------------------------------------------------------------------------
1 | #import "GeneratedPluginRegistrant.h"
--------------------------------------------------------------------------------
/img/img_a.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/img/img_a.png
--------------------------------------------------------------------------------
/img/pic_b.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/img/pic_b.png
--------------------------------------------------------------------------------
/android/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Xmx1536M
2 |
3 | android.useAndroidX=true
4 | android.enableJetifier=true
5 |
--------------------------------------------------------------------------------
/ios/Flutter/Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
2 | #include "Generated.xcconfig"
3 |
--------------------------------------------------------------------------------
/ios/Flutter/Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
2 | #include "Generated.xcconfig"
3 |
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhoujiulong/FlutterHttpUtils/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png
--------------------------------------------------------------------------------
/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Jun 23 08:50:38 CEST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
7 |
--------------------------------------------------------------------------------
/ios/Runner.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled and should not be manually edited.
5 |
6 | version:
7 | revision: 20e59316b8b8474554b38493b8ca888794b0234a
8 | channel: stable
9 |
10 | project_type: app
11 |
--------------------------------------------------------------------------------
/ios/Podfile.lock:
--------------------------------------------------------------------------------
1 | PODS:
2 | - Flutter (1.0.0)
3 |
4 | DEPENDENCIES:
5 | - Flutter (from `.symlinks/flutter/ios`)
6 |
7 | EXTERNAL SOURCES:
8 | Flutter:
9 | :path: ".symlinks/flutter/ios"
10 |
11 | SPEC CHECKSUMS:
12 | Flutter: 58dd7d1b27887414a370fcccb9e645c08ffd7a6a
13 |
14 | PODFILE CHECKSUM: b6a0a141693093b304368d08511b46cf3d1d0ac5
15 |
16 | COCOAPODS: 1.7.4
17 |
--------------------------------------------------------------------------------
/android/app/src/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/android/app/src/profile/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md:
--------------------------------------------------------------------------------
1 | # Launch Screen Assets
2 |
3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory.
4 |
5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images.
--------------------------------------------------------------------------------
/android/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
--------------------------------------------------------------------------------
/lib/http_util/base_response.dart:
--------------------------------------------------------------------------------
1 | ///返回对象封装
2 | class BaseResponse {
3 | BaseResponse(this.code, this.message, this.result);
4 |
5 | //后台返回的错误码
6 | int code;
7 | //返回的信息
8 | String message;
9 | //返回的数据,需要自己进行处理成自己想要的对象
10 | Map result;
11 |
12 | BaseResponse.fromJson(Map json)
13 | : code = json["code"],
14 | message = json["message"],
15 | result = json["result"];
16 | }
17 |
--------------------------------------------------------------------------------
/android/app/src/main/kotlin/com/example/flutter_http_utils/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.example.flutter_http_utils
2 |
3 | import android.os.Bundle
4 |
5 | import io.flutter.app.FlutterActivity
6 | import io.flutter.plugins.GeneratedPluginRegistrant
7 |
8 | class MainActivity: FlutterActivity() {
9 | override fun onCreate(savedInstanceState: Bundle?) {
10 | super.onCreate(savedInstanceState)
11 | GeneratedPluginRegistrant.registerWith(this)
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ios/Runner/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | import UIKit
2 | import Flutter
3 |
4 | @UIApplicationMain
5 | @objc class AppDelegate: FlutterAppDelegate {
6 | override func application(
7 | _ application: UIApplication,
8 | didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
9 | ) -> Bool {
10 | GeneratedPluginRegistrant.register(with: self)
11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions)
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/android/app/src/main/res/drawable/launch_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "LaunchImage.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "LaunchImage@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "filename" : "LaunchImage@3x.png",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/android/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
3 | def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
4 |
5 | def plugins = new Properties()
6 | def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
7 | if (pluginsFile.exists()) {
8 | pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
9 | }
10 |
11 | plugins.each { name, path ->
12 | def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
13 | include ":$name"
14 | project(":$name").projectDir = pluginDirectory
15 | }
16 |
--------------------------------------------------------------------------------
/lib/http_util/request_listener.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | import 'base_response.dart';
4 |
5 | ///网络请求监听
6 | class RequestListener {
7 | RequestListener({@required this.onSuccessListener, @required this.onErrorListener});
8 |
9 | //请求成功
10 | final ValueChanged onSuccessListener;
11 |
12 | //请求失败
13 | final ValueChanged onErrorListener;
14 |
15 | void onSuccess(BaseResponse response) {
16 | if (onSuccessListener != null) onSuccessListener(response);
17 | }
18 |
19 | void onError(BaseResponse response) {
20 | if (onErrorListener != null) onErrorListener(response);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.kotlin_version = '1.2.71'
3 | repositories {
4 | google()
5 | jcenter()
6 | }
7 |
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:3.2.1'
10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11 | }
12 | }
13 |
14 | allprojects {
15 | repositories {
16 | google()
17 | jcenter()
18 | }
19 | }
20 |
21 | rootProject.buildDir = '../build'
22 | subprojects {
23 | project.buildDir = "${rootProject.buildDir}/${project.name}"
24 | }
25 | subprojects {
26 | project.evaluationDependsOn(':app')
27 | }
28 |
29 | task clean(type: Delete) {
30 | delete rootProject.buildDir
31 | }
32 |
--------------------------------------------------------------------------------
/ios/Flutter/AppFrameworkInfo.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | App
9 | CFBundleIdentifier
10 | io.flutter.flutter.app
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | App
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1.0
23 | MinimumOSVersion
24 | 8.0
25 |
26 |
27 |
--------------------------------------------------------------------------------
/test/widget_test.dart:
--------------------------------------------------------------------------------
1 | // This is a basic Flutter widget test.
2 | //
3 | // To perform an interaction with a widget in your test, use the WidgetTester
4 | // utility that Flutter provides. For example, you can send tap and scroll
5 | // gestures. You can also use WidgetTester to find child widgets in the widget
6 | // tree, read text, and verify that the values of widget properties are correct.
7 |
8 | import 'package:flutter/material.dart';
9 | import 'package:flutter_test/flutter_test.dart';
10 |
11 | import 'package:flutter_http_utils/main.dart';
12 |
13 | void main() {
14 | testWidgets('Counter increments smoke test', (WidgetTester tester) async {
15 | // Build our app and trigger a frame.
16 | await tester.pumpWidget(MyApp());
17 |
18 | // Verify that our counter starts at 0.
19 | expect(find.text('0'), findsOneWidget);
20 | expect(find.text('1'), findsNothing);
21 |
22 | // Tap the '+' icon and trigger a frame.
23 | await tester.tap(find.byIcon(Icons.add));
24 | await tester.pump();
25 |
26 | // Verify that our counter has incremented.
27 | expect(find.text('0'), findsNothing);
28 | expect(find.text('1'), findsOneWidget);
29 | });
30 | }
31 |
--------------------------------------------------------------------------------
/lib/bloc/bloc_provider.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | abstract class BlocBase {
4 | void dispose();
5 | }
6 |
7 | ///简单封装,使用 StatefulWidget 主要是在 dispose 对资源进行释放
8 | class BlocProvider extends StatefulWidget {
9 | BlocProvider({
10 | Key key,
11 | @required this.child,
12 | @required this.bloc,
13 | this.userDispose: true,
14 | }) : super(key: key);
15 |
16 | final T bloc;
17 | final Widget child;
18 | final bool userDispose;
19 |
20 | @override
21 | _BlocProviderState createState() => _BlocProviderState();
22 |
23 | ///这个方法会从副控件的变量中进行查找,将最近的父控件中的 T 进行返回
24 | static T of(BuildContext context) {
25 | final type = _typeOf>();
26 | BlocProvider provider = context.ancestorWidgetOfExactType(type);
27 | return provider.bloc;
28 | }
29 |
30 | static Type _typeOf() => T;
31 | }
32 |
33 | class _BlocProviderState extends State> {
34 | @override
35 | void dispose() {
36 | if (widget.userDispose) widget.bloc.dispose();
37 | super.dispose();
38 | }
39 |
40 | @override
41 | Widget build(BuildContext context) {
42 | return widget.child;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/lib/bloc/music_bloc.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter_http_utils/bean/music.dart';
2 | import 'package:flutter_http_utils/http_util/base_response.dart';
3 | import 'package:flutter_http_utils/http_util/my_http_util.dart';
4 | import 'package:flutter_http_utils/http_util/request_listener.dart';
5 | import 'package:rxdart/rxdart.dart';
6 |
7 | import 'bloc_provider.dart';
8 |
9 | ///music 业务处理
10 | class MusicBloc implements BlocBase {
11 |
12 | BehaviorSubject _musicSubject = BehaviorSubject();
13 |
14 | Sink get _musicSink => _musicSubject.sink;
15 |
16 | Stream get musicStream => _musicSubject.stream;
17 |
18 | //发送请求
19 | getMusic() {
20 | MyHttpUtil.instance.post(
21 | "musicBroadcastingDetails?channelname=public_tuijian_spring",
22 | RequestListener(
23 | onSuccessListener: (BaseResponse data) => _onResponseSuccess(data),
24 | onErrorListener: (BaseResponse errorData) => _onResponseError(errorData)));
25 | }
26 |
27 | //请求成功
28 | _onResponseSuccess(BaseResponse data) {
29 | Music bean = Music.fromJson(data.result);
30 | _musicSink.add(bean);
31 | }
32 |
33 | //请求失败
34 | _onResponseError(BaseResponse data) {
35 | _musicSink.add(null);
36 | }
37 |
38 | @override
39 | void dispose() {
40 | _musicSubject.close();
41 | }
42 |
43 | }
--------------------------------------------------------------------------------
/lib/bean/music.dart:
--------------------------------------------------------------------------------
1 | import 'package:json_annotation/json_annotation.dart';
2 |
3 | part 'music.g.dart';
4 |
5 | ///这个标注是告诉生成器,这个类是需要生成Model类的
6 | @JsonSerializable()
7 | class Music extends Object {
8 | Music(
9 | {this.channel, this.title, this.count, this.ch_name, this.artistid, this.avatar, this.channelid, this.songlist});
10 |
11 | String channel;
12 | String title;
13 | int count;
14 | String ch_name;
15 | String artistid;
16 | String avatar;
17 | int channelid;
18 | List songlist;
19 |
20 | factory Music.fromJson(Map json) => _$MusicFromJson(json);
21 |
22 | Map toJson() => _$MusicToJson(this);
23 | }
24 |
25 | ///这个标注是告诉生成器,这个类是需要生成Model类的
26 | @JsonSerializable()
27 | class Song {
28 | Song(
29 | {this.all_rate,
30 | this.charge,
31 | this.method,
32 | this.artist,
33 | this.thumb,
34 | this.all_artist_id,
35 | this.resource_type,
36 | this.havehigh,
37 | this.title,
38 | this.songid,
39 | this.artist_id,
40 | this.flow});
41 |
42 | String all_rate;
43 | int charge;
44 | int method;
45 | String artist;
46 | String thumb;
47 | String all_artist_id;
48 | String resource_type;
49 | int havehigh;
50 | String title;
51 | String songid;
52 | String artist_id;
53 | int flow;
54 |
55 | factory Song.fromJson(Map json) => _$SongFromJson(json);
56 |
57 | Map toJson() => _$SongToJson(this);
58 | }
59 |
--------------------------------------------------------------------------------
/ios/Runner/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/ios/Runner/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | flutter_http_utils
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | $(FLUTTER_BUILD_NAME)
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | $(FLUTTER_BUILD_NUMBER)
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UISupportedInterfaceOrientations
30 |
31 | UIInterfaceOrientationPortrait
32 | UIInterfaceOrientationLandscapeLeft
33 | UIInterfaceOrientationLandscapeRight
34 |
35 | UISupportedInterfaceOrientations~ipad
36 |
37 | UIInterfaceOrientationPortrait
38 | UIInterfaceOrientationPortraitUpsideDown
39 | UIInterfaceOrientationLandscapeLeft
40 | UIInterfaceOrientationLandscapeRight
41 |
42 | UIViewControllerBasedStatusBarAppearance
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Miscellaneous
2 | *.class
3 | *.log
4 | *.pyc
5 | *.swp
6 | .DS_Store
7 | .atom/
8 | .buildlog/
9 | .history
10 | .svn/
11 |
12 | # IntelliJ related
13 | *.iml
14 | *.ipr
15 | *.iws
16 | .idea/
17 |
18 | # The .vscode folder contains launch configuration and tasks you configure in
19 | # VS Code which you may wish to be included in version control, so this line
20 | # is commented out by default.
21 | #.vscode/
22 |
23 | # Flutter/Dart/Pub related
24 | **/doc/api/
25 | .dart_tool/
26 | .flutter-plugins
27 | .packages
28 | .pub-cache/
29 | .pub/
30 | /build/
31 |
32 | # Android related
33 | **/android/**/gradle-wrapper.jar
34 | **/android/.gradle
35 | **/android/captures/
36 | **/android/gradlew
37 | **/android/gradlew.bat
38 | **/android/local.properties
39 | **/android/**/GeneratedPluginRegistrant.java
40 |
41 | # iOS/XCode related
42 | **/ios/**/*.mode1v3
43 | **/ios/**/*.mode2v3
44 | **/ios/**/*.moved-aside
45 | **/ios/**/*.pbxuser
46 | **/ios/**/*.perspectivev3
47 | **/ios/**/*sync/
48 | **/ios/**/.sconsign.dblite
49 | **/ios/**/.tags*
50 | **/ios/**/.vagrant/
51 | **/ios/**/DerivedData/
52 | **/ios/**/Icon?
53 | **/ios/**/Pods/
54 | **/ios/**/.symlinks/
55 | **/ios/**/profile
56 | **/ios/**/xcuserdata
57 | **/ios/.generated/
58 | **/ios/Flutter/App.framework
59 | **/ios/Flutter/Flutter.framework
60 | **/ios/Flutter/Generated.xcconfig
61 | **/ios/Flutter/app.flx
62 | **/ios/Flutter/app.zip
63 | **/ios/Flutter/flutter_assets/
64 | **/ios/ServiceDefinitions.json
65 | **/ios/Runner/GeneratedPluginRegistrant.*
66 |
67 | # Exceptions to above rules.
68 | !**/ios/**/default.mode1v3
69 | !**/ios/**/default.mode2v3
70 | !**/ios/**/default.pbxuser
71 | !**/ios/**/default.perspectivev3
72 | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
73 |
--------------------------------------------------------------------------------
/android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
9 |
10 |
14 |
21 |
25 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/android/app/build.gradle:
--------------------------------------------------------------------------------
1 | def localProperties = new Properties()
2 | def localPropertiesFile = rootProject.file('local.properties')
3 | if (localPropertiesFile.exists()) {
4 | localPropertiesFile.withReader('UTF-8') { reader ->
5 | localProperties.load(reader)
6 | }
7 | }
8 |
9 | def flutterRoot = localProperties.getProperty('flutter.sdk')
10 | if (flutterRoot == null) {
11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12 | }
13 |
14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
15 | if (flutterVersionCode == null) {
16 | flutterVersionCode = '1'
17 | }
18 |
19 | def flutterVersionName = localProperties.getProperty('flutter.versionName')
20 | if (flutterVersionName == null) {
21 | flutterVersionName = '1.0'
22 | }
23 |
24 | apply plugin: 'com.android.application'
25 | apply plugin: 'kotlin-android'
26 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
27 |
28 | android {
29 | compileSdkVersion 28
30 |
31 | sourceSets {
32 | main.java.srcDirs += 'src/main/kotlin'
33 | }
34 |
35 | lintOptions {
36 | disable 'InvalidPackage'
37 | }
38 |
39 | defaultConfig {
40 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
41 | applicationId "com.example.flutter_http_utils"
42 | minSdkVersion 16
43 | targetSdkVersion 28
44 | versionCode flutterVersionCode.toInteger()
45 | versionName flutterVersionName
46 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
47 | }
48 |
49 | buildTypes {
50 | release {
51 | // TODO: Add your own signing config for the release build.
52 | // Signing with the debug keys for now, so `flutter run --release` works.
53 | signingConfig signingConfigs.debug
54 | }
55 | }
56 | }
57 |
58 | flutter {
59 | source '../..'
60 | }
61 |
62 | dependencies {
63 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
64 | testImplementation 'junit:junit:4.12'
65 | androidTestImplementation 'androidx.test:runner:1.1.1'
66 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
67 | implementation 'com.android.support:support-v4:28.0.0'
68 | }
69 |
--------------------------------------------------------------------------------
/lib/bean/music.g.dart:
--------------------------------------------------------------------------------
1 | // GENERATED CODE - DO NOT MODIFY BY HAND
2 |
3 | part of 'music.dart';
4 |
5 | // **************************************************************************
6 | // JsonSerializableGenerator
7 | // **************************************************************************
8 |
9 | Music _$MusicFromJson(Map json) {
10 | return Music(
11 | channel: json['channel'] as String,
12 | title: json['title'] as String,
13 | count: json['count'] as int,
14 | ch_name: json['ch_name'] as String,
15 | artistid: json['artistid'] as String,
16 | avatar: json['avatar'] as String,
17 | channelid: json['channelid'] as int,
18 | songlist: (json['songlist'] as List)
19 | ?.map((e) =>
20 | e == null ? null : Song.fromJson(e as Map))
21 | ?.toList());
22 | }
23 |
24 | Map _$MusicToJson(Music instance) => {
25 | 'channel': instance.channel,
26 | 'title': instance.title,
27 | 'count': instance.count,
28 | 'ch_name': instance.ch_name,
29 | 'artistid': instance.artistid,
30 | 'avatar': instance.avatar,
31 | 'channelid': instance.channelid,
32 | 'songlist': instance.songlist
33 | };
34 |
35 | Song _$SongFromJson(Map json) {
36 | return Song(
37 | all_rate: json['all_rate'] as String,
38 | charge: json['charge'] as int,
39 | method: json['method'] as int,
40 | artist: json['artist'] as String,
41 | thumb: json['thumb'] as String,
42 | all_artist_id: json['all_artist_id'] as String,
43 | resource_type: json['resource_type'] as String,
44 | havehigh: json['havehigh'] as int,
45 | title: json['title'] as String,
46 | songid: json['songid'] as String,
47 | artist_id: json['artist_id'] as String,
48 | flow: json['flow'] as int);
49 | }
50 |
51 | Map _$SongToJson(Song instance) => {
52 | 'all_rate': instance.all_rate,
53 | 'charge': instance.charge,
54 | 'method': instance.method,
55 | 'artist': instance.artist,
56 | 'thumb': instance.thumb,
57 | 'all_artist_id': instance.all_artist_id,
58 | 'resource_type': instance.resource_type,
59 | 'havehigh': instance.havehigh,
60 | 'title': instance.title,
61 | 'songid': instance.songid,
62 | 'artist_id': instance.artist_id,
63 | 'flow': instance.flow
64 | };
65 |
--------------------------------------------------------------------------------
/ios/Runner/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/ios/Podfile:
--------------------------------------------------------------------------------
1 | # Uncomment this line to define a global platform for your project
2 | # platform :ios, '9.0'
3 |
4 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency.
5 | ENV['COCOAPODS_DISABLE_STATS'] = 'true'
6 |
7 | project 'Runner', {
8 | 'Debug' => :debug,
9 | 'Profile' => :release,
10 | 'Release' => :release,
11 | }
12 |
13 | def parse_KV_file(file, separator='=')
14 | file_abs_path = File.expand_path(file)
15 | if !File.exists? file_abs_path
16 | return [];
17 | end
18 | pods_ary = []
19 | skip_line_start_symbols = ["#", "/"]
20 | File.foreach(file_abs_path) { |line|
21 | next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
22 | plugin = line.split(pattern=separator)
23 | if plugin.length == 2
24 | podname = plugin[0].strip()
25 | path = plugin[1].strip()
26 | podpath = File.expand_path("#{path}", file_abs_path)
27 | pods_ary.push({:name => podname, :path => podpath});
28 | else
29 | puts "Invalid plugin specification: #{line}"
30 | end
31 | }
32 | return pods_ary
33 | end
34 |
35 | target 'Runner' do
36 | use_frameworks!
37 |
38 | # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
39 | # referring to absolute paths on developers' machines.
40 | system('rm -rf .symlinks')
41 | system('mkdir -p .symlinks/plugins')
42 |
43 | # Flutter Pods
44 | generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig')
45 | if generated_xcode_build_settings.empty?
46 | puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first."
47 | end
48 | generated_xcode_build_settings.map { |p|
49 | if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
50 | symlink = File.join('.symlinks', 'flutter')
51 | File.symlink(File.dirname(p[:path]), symlink)
52 | pod 'Flutter', :path => File.join(symlink, File.basename(p[:path]))
53 | end
54 | }
55 |
56 | # Plugin Pods
57 | plugin_pods = parse_KV_file('../.flutter-plugins')
58 | plugin_pods.map { |p|
59 | symlink = File.join('.symlinks', 'plugins', p[:name])
60 | File.symlink(p[:path], symlink)
61 | pod p[:name], :path => File.join(symlink, 'ios')
62 | }
63 | end
64 |
65 | # Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system.
66 | install! 'cocoapods', :disable_input_output_paths => true
67 |
68 | post_install do |installer|
69 | installer.pods_project.targets.each do |target|
70 | target.build_configurations.each do |config|
71 | config.build_settings['ENABLE_BITCODE'] = 'NO'
72 | end
73 | end
74 | end
75 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 基于 dio 封装的网络请求框架
2 | -------------
3 | ### 项目简介
4 | 项目中基本会用到网络请求,flutter 中有 dio 网络请求框架项目地址:https://github.com/flutterchina/dio,
5 | 而在实际开发中我们在请求的时候会添加一些头部信息和后台进行一些校验和一些公共信息的传递如版本号等,同时针对返回的
6 | 信息我们会定义一套数据结构模版如前后台协同定义的状态码,如区分token失效等,所以在开发中我们需要对网络框架进行进
7 | 一步的封装来达到统一处理类似切面编程的效果,同时对网络请求框架进行进一步封装之后也方便后期对网络请求框架的替换,
8 | 因为在实际的使用中我们是可以不引用网络框架代码的。
9 | 项目中添加来 bloc 框架的使用,使得页面和逻辑层相互独立,具体参考参考:https://www.jianshu.com/p/4d5e712594b4
10 | ### 使用方式
11 | 1、在项目中的 pubspec.yaml 文件中添加 dio: 2.1.13 的支持,如果不需要json序列化可不添加json_serializable相
12 | 关的库,依赖如下:
13 | dependencies:
14 | flutter:
15 | sdk: flutter
16 |
17 | cupertino_icons: ^0.1.2
18 | #网络请求库
19 | dio: 2.1.13
20 | #json序列化库 :json_serializable
21 | json_annotation: ^2.0.0
22 | #bloc 框架使用时用到,不用到 bloc 框架的可不添加
23 | rxdart: ^0.19.0
24 |
25 | dev_dependencies:
26 | flutter_test:
27 | sdk: flutter
28 | #json序列化库 :json_serializable
29 | build_runner: ^1.0.0
30 | #json序列化库 :json_serializable
31 | json_serializable: ^2.0.0
32 | 2、将本项目中 lib 下 http_util 包考进自己项目中
33 | 3、在需要使用的地方导入 MyHttpUtil.dart、BaseResponse.dart、RequestListener.dart文件
34 | 4、发送请求:
35 | //Post请求
36 | _sendPostRequest() {
37 | MyHttpUtil.instance.post(
38 | "musicBroadcastingDetails?channelname=public_tuijian_spring",
39 | RequestListener(
40 | onSuccessListener: (BaseResponse data) => _onResponseSuccess(data),
41 | onErrorListener: (BaseResponse errorData) => _onResponseError(errorData)
42 | )
43 | );
44 | }
45 |
46 | //Get请求
47 | _sendGetRequest() {
48 | MyHttpUtil.instance.get(
49 | "musicBroadcastingDetails?channelname=public_tuijian_spring",
50 | RequestListener(
51 | onSuccessListener: (BaseResponse data) => _onResponseSuccess(data),
52 | onErrorListener: (BaseResponse errorData) => _onResponseError(errorData)
53 | )
54 | );
55 | }
56 | 5、如果需要添加请求头、拦截器,修改一些参数,在MyHttpUtil.dart中进行修改,参考备注
57 | ### 友情提示
58 | 如果下载此项目在mac运行在ios设备上报 Podfile.lock 相关错误,尝试用终端进入到ios目录下执行 pod install 命令
59 | 习惯安卓开发的朋友可能习惯来安卓 json 解析的方式,在 flutter 开发时候对 flutter json 解析可能一下不是很适应,
60 | 因为 flutter json 解析需要额外做一些处理,可以参考下面这篇文章(在 Flutter 中解析复杂的 JSON)
61 | 当然flutter也有一些开源库是针对 json 解的,如 json_serializable package,具体使用方法参考下面这篇文章(使用
62 | 代码生成库序列化JSON),part 导入的时候名称要和文件名相同不然会运行 flutter packages pub run build_runner build 错误
63 | [在 Flutter 中解析复杂的 JSON](https://github.com/xitu/gold-miner/blob/master/TODO1/parsing-complex-json-in-flutter.md)
64 | [使用代码生成库序列化JSON](https://flutterchina.club/json/)
65 | ### demo 代码运行效果如下
66 |
67 |
68 |
--------------------------------------------------------------------------------
/lib/main.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:flutter_http_utils/bean/music.dart';
3 |
4 | import 'bloc/bloc_provider.dart';
5 | import 'bloc/music_bloc.dart';
6 |
7 | void main() => runApp(MyApp());
8 |
9 | class MyApp extends StatelessWidget {
10 | @override
11 | Widget build(BuildContext context) {
12 | return BlocProvider(
13 | bloc: MusicBloc(),
14 | child: MaterialApp(
15 | title: 'Flutter Demo',
16 | theme: ThemeData(
17 | primarySwatch: Colors.blue,
18 | ),
19 | home: MyHomePage(),
20 | ),
21 | );
22 | }
23 | }
24 |
25 | class MyHomePage extends StatelessWidget {
26 | @override
27 | Widget build(BuildContext context) {
28 | MusicBloc bloc = BlocProvider.of(context);
29 |
30 | return Scaffold(
31 | appBar: AppBar(
32 | title: Text("http util"),
33 | ),
34 | body: StreamBuilder(
35 | stream: bloc.musicStream,
36 | builder: (BuildContext context, AsyncSnapshot snapshot) {
37 | //如果数据为空则返回获取数据按钮
38 | if (snapshot.data == null) {
39 | return Center(
40 | child: FlatButton(
41 | onPressed: () {
42 | bloc.getMusic();
43 | },
44 | child: Text('点击获取网络数据'),
45 | color: Colors.green,
46 | ),
47 | );
48 | }
49 | //列表显示返回的数据
50 | return ListView.builder(
51 | itemCount: snapshot.data.songlist.length,
52 | itemBuilder: (context, index) {
53 | return ListTile(
54 | title: _buildItem(snapshot.data.songlist[index]),
55 | );
56 | },
57 | );
58 | }),
59 | );
60 | }
61 |
62 | //创建 item
63 | Widget _buildItem(Song data) {
64 | if (data == null) data = Song();
65 | String title = data.title != null ? data.title : "未知标题";
66 | String artist = data.artist != null ? data.artist : "未知艺术家";
67 | String imgSrc = data.thumb != null ? data.thumb : "";
68 |
69 | return Row(
70 | mainAxisAlignment: MainAxisAlignment.start,
71 | crossAxisAlignment: CrossAxisAlignment.start,
72 | children: [
73 | Container(
74 | width: 80,
75 | height: 80,
76 | child: Image.network(
77 | imgSrc,
78 | fit: BoxFit.fill,
79 | ),
80 | ),
81 | Padding(
82 | padding: EdgeInsets.only(left: 20),
83 | child: Column(
84 | mainAxisAlignment: MainAxisAlignment.start,
85 | crossAxisAlignment: CrossAxisAlignment.start,
86 | children: [
87 | Text(title),
88 | Padding(
89 | padding: EdgeInsets.only(top: 20),
90 | child: Text(artist),
91 | ),
92 | ],
93 | ),
94 | ),
95 | ],
96 | );
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: flutter_http_utils
2 | description: A new Flutter application.
3 |
4 | # The following defines the version and build number for your application.
5 | # A version number is three numbers separated by dots, like 1.2.43
6 | # followed by an optional build number separated by a +.
7 | # Both the version and the builder number may be overridden in flutter
8 | # build by specifying --build-name and --build-number, respectively.
9 | # In Android, build-name is used as versionName while build-number used as versionCode.
10 | # Read more about Android versioning at https://developer.android.com/studio/publish/versioning
11 | # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
12 | # Read more about iOS versioning at
13 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
14 | version: 1.0.0+1
15 |
16 | environment:
17 | sdk: ">=2.2.0 <3.0.0"
18 |
19 | dependencies:
20 | flutter:
21 | sdk: flutter
22 |
23 | # The following adds the Cupertino Icons font to your application.
24 | # Use with the CupertinoIcons class for iOS style icons.
25 | cupertino_icons: ^0.1.2
26 | dio: 2.1.13
27 | json_annotation: ^2.0.0
28 | rxdart: ^0.19.0
29 |
30 | dev_dependencies:
31 | flutter_test:
32 | sdk: flutter
33 | build_runner: ^1.0.0
34 | json_serializable: ^2.0.0
35 |
36 |
37 | # For information on the generic Dart part of this file, see the
38 | # following page: https://dart.dev/tools/pub/pubspec
39 |
40 | # The following section is specific to Flutter.
41 | flutter:
42 |
43 | # The following line ensures that the Material Icons font is
44 | # included with your application, so that you can use the icons in
45 | # the material Icons class.
46 | uses-material-design: true
47 |
48 | # To add assets to your application, add an assets section, like this:
49 | # assets:
50 | # - images/a_dot_burr.jpeg
51 | # - images/a_dot_ham.jpeg
52 |
53 | # An image asset can refer to one or more resolution-specific "variants", see
54 | # https://flutter.dev/assets-and-images/#resolution-aware.
55 |
56 | # For details regarding adding assets from package dependencies, see
57 | # https://flutter.dev/assets-and-images/#from-packages
58 |
59 | # To add custom fonts to your application, add a fonts section here,
60 | # in this "flutter" section. Each entry in this list should have a
61 | # "family" key with the font family name, and a "fonts" key with a
62 | # list giving the asset and other descriptors for the font. For
63 | # example:
64 | # fonts:
65 | # - family: Schyler
66 | # fonts:
67 | # - asset: fonts/Schyler-Regular.ttf
68 | # - asset: fonts/Schyler-Italic.ttf
69 | # style: italic
70 | # - family: Trajan Pro
71 | # fonts:
72 | # - asset: fonts/TrajanPro.ttf
73 | # - asset: fonts/TrajanPro_Bold.ttf
74 | # weight: 700
75 | #
76 | # For details regarding fonts from package dependencies,
77 | # see https://flutter.dev/custom-fonts/#from-packages
78 |
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "size" : "20x20",
5 | "idiom" : "iphone",
6 | "filename" : "Icon-App-20x20@2x.png",
7 | "scale" : "2x"
8 | },
9 | {
10 | "size" : "20x20",
11 | "idiom" : "iphone",
12 | "filename" : "Icon-App-20x20@3x.png",
13 | "scale" : "3x"
14 | },
15 | {
16 | "size" : "29x29",
17 | "idiom" : "iphone",
18 | "filename" : "Icon-App-29x29@1x.png",
19 | "scale" : "1x"
20 | },
21 | {
22 | "size" : "29x29",
23 | "idiom" : "iphone",
24 | "filename" : "Icon-App-29x29@2x.png",
25 | "scale" : "2x"
26 | },
27 | {
28 | "size" : "29x29",
29 | "idiom" : "iphone",
30 | "filename" : "Icon-App-29x29@3x.png",
31 | "scale" : "3x"
32 | },
33 | {
34 | "size" : "40x40",
35 | "idiom" : "iphone",
36 | "filename" : "Icon-App-40x40@2x.png",
37 | "scale" : "2x"
38 | },
39 | {
40 | "size" : "40x40",
41 | "idiom" : "iphone",
42 | "filename" : "Icon-App-40x40@3x.png",
43 | "scale" : "3x"
44 | },
45 | {
46 | "size" : "60x60",
47 | "idiom" : "iphone",
48 | "filename" : "Icon-App-60x60@2x.png",
49 | "scale" : "2x"
50 | },
51 | {
52 | "size" : "60x60",
53 | "idiom" : "iphone",
54 | "filename" : "Icon-App-60x60@3x.png",
55 | "scale" : "3x"
56 | },
57 | {
58 | "size" : "20x20",
59 | "idiom" : "ipad",
60 | "filename" : "Icon-App-20x20@1x.png",
61 | "scale" : "1x"
62 | },
63 | {
64 | "size" : "20x20",
65 | "idiom" : "ipad",
66 | "filename" : "Icon-App-20x20@2x.png",
67 | "scale" : "2x"
68 | },
69 | {
70 | "size" : "29x29",
71 | "idiom" : "ipad",
72 | "filename" : "Icon-App-29x29@1x.png",
73 | "scale" : "1x"
74 | },
75 | {
76 | "size" : "29x29",
77 | "idiom" : "ipad",
78 | "filename" : "Icon-App-29x29@2x.png",
79 | "scale" : "2x"
80 | },
81 | {
82 | "size" : "40x40",
83 | "idiom" : "ipad",
84 | "filename" : "Icon-App-40x40@1x.png",
85 | "scale" : "1x"
86 | },
87 | {
88 | "size" : "40x40",
89 | "idiom" : "ipad",
90 | "filename" : "Icon-App-40x40@2x.png",
91 | "scale" : "2x"
92 | },
93 | {
94 | "size" : "76x76",
95 | "idiom" : "ipad",
96 | "filename" : "Icon-App-76x76@1x.png",
97 | "scale" : "1x"
98 | },
99 | {
100 | "size" : "76x76",
101 | "idiom" : "ipad",
102 | "filename" : "Icon-App-76x76@2x.png",
103 | "scale" : "2x"
104 | },
105 | {
106 | "size" : "83.5x83.5",
107 | "idiom" : "ipad",
108 | "filename" : "Icon-App-83.5x83.5@2x.png",
109 | "scale" : "2x"
110 | },
111 | {
112 | "size" : "1024x1024",
113 | "idiom" : "ios-marketing",
114 | "filename" : "Icon-App-1024x1024@1x.png",
115 | "scale" : "1x"
116 | }
117 | ],
118 | "info" : {
119 | "version" : 1,
120 | "author" : "xcode"
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/lib/http_util/my_http_util.dart:
--------------------------------------------------------------------------------
1 | import 'package:dio/dio.dart';
2 |
3 | import 'request_listener.dart';
4 | import 'base_response.dart';
5 |
6 | ///网络请求工具类,单例处理
7 | class MyHttpUtil {
8 | static const String _GET = "get";
9 | static const String _POST = "post";
10 | static const int _COMMON_REQUEST_ERROR = -1;
11 |
12 | Dio _dio;
13 | static MyHttpUtil _instance;
14 |
15 | static MyHttpUtil get instance => _getInstance();
16 |
17 | factory MyHttpUtil() => _getInstance();
18 |
19 | static MyHttpUtil _getInstance() {
20 | if (_instance == null) {
21 | _instance = MyHttpUtil._internal();
22 | }
23 | return _instance;
24 | }
25 |
26 | ///初始化
27 | MyHttpUtil._internal() {
28 | _dio = Dio(BaseOptions(
29 | //项目域名,如果传的 url 是以 http 开头的会忽略此域名
30 | baseUrl: "https://api.apiopen.top/",
31 | //请求头
32 | headers: {'platform': 'android', 'version': 11.0},
33 | connectTimeout: 10000,
34 | receiveTimeout: 20000,
35 | ));
36 | _addStartHttpInterceptor(_dio); //添加请求之前的拦截器
37 | }
38 |
39 | ///get请求
40 | ///如果 url 是以 http 开头的则忽略 baseUrl
41 | get(String url, RequestListener requestListener, {params}) async {
42 | _requestHttp(url, requestListener, _GET, params);
43 | }
44 |
45 | ///post请求
46 | ///如果 url 是以 http 开头的则忽略 baseUrl
47 | post(String url, RequestListener requestListener, {params}) async {
48 | _requestHttp(url, requestListener, _POST, params);
49 | }
50 |
51 | ///网络请求
52 | _requestHttp(String url, RequestListener requestListener, [String method, FormData params]) async {
53 | try {
54 | Response