Coder Social home page Coder Social logo

Comments (5)

mogocat avatar mogocat commented on June 20, 2024 1

添加了一个示例

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  MyApp (){
    var dio = new Dio();
    dio.get("https://www.baidu.com").then((response) {
      print(response.data);
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Welcome to Flutter'),
        ),
        body: Center(
          child: Text('Hello World'),
        ),
      ),
    );
  }
}

from dio.

mogocat avatar mogocat commented on June 20, 2024

我是dart新手,flutter内置了dart2,await和async貌似要被换成then的语法,采用Future类型实现具体参照这篇帖子

Dio dio = new Dio();
Response response=await dio.get("https://www.google.com/");
print(response.data);

需要修改为
need to be changed to

 Dio dio = new Dio();
 dio.get("https://www.baidu.com").then((response) {print(response.data);});

目前运行良好
It works for now

from dio.

wendux avatar wendux commented on June 20, 2024

@mogocat 不是的,你需要把代码放到async函数中才能使用await,示例代码是片段,你可以查看工程example下的完整示例。

from dio.

mogocat avatar mogocat commented on June 20, 2024

@wendux 感谢回复,我用then调用了,能正常使用。

from dio.

mogocat avatar mogocat commented on June 20, 2024

抱歉我只是按照教程敲Widget上手,对这些不太熟悉。如果其他人也按照文档教程写Widget上手的话,建议还是用then,如果熟悉async和await用法,再参照example。

from dio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.