zoukankan      html  css  js  c++  java
  • flutter 正式配置网络框架

    service_url.dart 代码

    const serviceUrl = 'https://wxmini.baixingliangfan.cn/baixing/';
    const servicePath = {
    'homePageContent' : serviceUrl + 'wxmini/homePageContent',//商店首页信息
    };
    service_method.dart 代码
    import 'package:dio/dio.dart';
    import 'dart:async';
    import 'dart:io';//contentType
    import '../config/service_url.dart';
    //获取首页主题内容
    Future getHomePageContent() async {
    try {
    print('开始获取首页内容');
    Response homeRes;
    Dio dio = new Dio();
    dio.options.contentType = ContentType.parse("application/x-www-form-urlencoded");
    var formData = {'lon' : '115.02932','lat':'35.76189'};
    homeRes = await dio.post(servicePath['homePageContent'],data: formData);
    if (homeRes.statusCode == 200) {
    return homeRes.data;
    }else{
    return Exception('接口异常');
    }

    } catch (e) {
    return print('ERROR:==========>${e}');
    }



    }
    总结:
     

    //正式的项目网络配置

    以下的dart 文件名都是自定义

    会有一个统一管理管理地址的service_url.dart

    然后 会把各个接口请求 都写在一个公共的service_method.dart 引入 Dio 和 Service_url.dart 等文件

    最后 正式页面请求 都只引入 service_method.dart 即可

  • 相关阅读:
    python爬虫之Anaconda安装
    python爬虫之scrapy安装(一)
    python爬虫之redis环境简单部署
    python爬虫之Phantomjs安装和使用
    python爬虫之win7Mongod安装使用
    python爬虫之PyQuery的基本使用
    python爬虫之xpath的基本使用
    python爬虫之git的使用(windows下pycharm使用)
    Sass教程
    Vue.js教程—1.介绍和安装
  • 原文地址:https://www.cnblogs.com/pp-pping/p/12222085.html
Copyright © 2011-2022 走看看