get_user.dart 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // ignore_for_file: library_private_types_in_public_api
  2. import 'package:dio/dio.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:namer_app/globals.dart';
  5. final globalState = _GlobalsState();
  6. void main() {
  7. globalState.getuser();//call this way
  8. runApp(
  9. MaterialApp(
  10. debugShowCheckedModeBanner: false,
  11. title: "Taxiyee_Messaging_app",
  12. home: Container(),
  13. ),
  14. );
  15. }
  16. class Globals extends StatefulWidget {
  17. const Globals({super.key});
  18. @override
  19. _GlobalsState createState() => _GlobalsState();
  20. }
  21. class _GlobalsState extends State<Globals> {
  22. // int counter = 0;
  23. var jsonList = '';
  24. @override
  25. Widget build(BuildContext context) {
  26. return Container();
  27. }
  28. getuser() async{
  29. try {
  30. var response = await Dio()
  31. .get('http://localhost:8080/api/v1/users',
  32. options: Options(headers: headers));
  33. // print('Method Call');
  34. if (response.statusCode == 200) {
  35. setState(() {
  36. // counter++;
  37. jsonList = response.data['results'];
  38. });}
  39. } on Exception catch (e) {
  40. print(e);
  41. }
  42. }
  43. }