get_user.dart 797 B

1234567891011121314151617181920212223242526272829303132333435
  1. // ignore_for_file: camel_case_types
  2. import 'package:dio/dio.dart';
  3. import 'package:flutter/material.dart';
  4. import '../globals.dart';
  5. class _getuser extends StatefulWidget {
  6. const _getuser();
  7. @override
  8. State<_getuser> createState() => _getuserState();
  9. }
  10. class _getuserState extends State<_getuser> {
  11. late List jsonList;
  12. void getuser() async {
  13. try {
  14. var response = await Dio()
  15. .get('http://localhost:8080/api/v1/users',
  16. options: Options(headers: headers));
  17. if (response.statusCode == 200) {
  18. setState(() {
  19. jsonList = response.data['results'] as List;
  20. });
  21. }
  22. } catch (e) {
  23. print(e);
  24. }
  25. }
  26. @override
  27. dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
  28. }