name27 / flutter

0 stars 0 forks source link

error handling #71

Open name27 opened 1 year ago

name27 commented 1 year ago

image

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  var dio = Dio();
  var url = "https://sniperfactory.com/sfac/http_";

  void getDataUsingDio() async {
    int i = 20;
    for (int i = 20; i <= 50; i++) {
      try {
        var res = await dio.get(url + i.toString());
        print('${url + i.toString()} = $res');
      } catch (e) {
        print(e);
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(),
        body: Center(
            child: TextButton(
          onPressed: () {
            getDataUsingDio();
            setState(() {});
          },
          child: Text('스나이퍼팩토리 비밀url'),
        )),
      ),
    );
  }
}