美文网首页
2.get post请求

2.get post请求

作者: 冰点雨 | 来源:发表于2019-12-23 13:55 被阅读0次
    b4093863d31630533a3522174d4dd74.png
    import 'package:flutter/material.dart';
    import 'package:dio/dio.dart';
    
    class HomePage extends StatefulWidget {
      _HomePageState createState() => _HomePageState();
    }
    
    
    class _HomePageState extends State<HomePage>{
    
      TextEditingController typeController = TextEditingController();
      String showText = '欢迎你来到美好人间';
    
    
      @override
      Widget build(BuildContext context){
        return Container(
    
          child: Scaffold(
            appBar: AppBar(title: Text('9999'),),
            body: SingleChildScrollView(
              child: Container(
                height: 1000,
                child: Column(
                  children: <Widget>[
                    TextField(
                      controller: typeController,
                      decoration: InputDecoration(
                        contentPadding: EdgeInsets.all(10.0),
                        labelText: '类型',
                        helperText: '请输入你喜欢的类型',
                      ),
                      autofocus: false,
                    ),
    
                    RaisedButton(
                      onPressed: _choiceAction,
                      child: Text('选择完成'),
                    ),
    
                    Text(
                      showText,
                      overflow: TextOverflow.ellipsis,
                      maxLines: 1,
                    ),
                  ],
                ),
              ),
            )
          ),
    
        );
      }
    
      void _choiceAction(){
    
        if (typeController.text.toString() == '') {
          showDialog(
              context: context,
              builder: (context)=>AlertDialog(title:Text('美女类型不能为空'))
          );
        }else{
          getHttp(typeController.text.toString()).then((val){
          setState(() {
          showText=val['data']['name'].toString();
          });
    
          });
    
    
        }
    
      }
    
    
    
    
    
    
    
    
      Future getHttp(String TypeText)async{
        try{
          Response response;
          var data={'name':TypeText};
          response = await Dio().post(
              "https://www.easy-mock.com/mock/5c60131a4bed3a6342711498/baixing/dabaojian",
              queryParameters:data
          );
          return response.data;
        }catch(e){
          return print(e);
        }
      }
    }
    

    相关文章

      网友评论

          本文标题:2.get post请求

          本文链接:https://www.haomeiwen.com/subject/vvpznctx.html