Flutter -> Flask SocketException (SocketException: OS Error: Connection refused, errno = 111, address = 127.0.0.1, port = 50484)

Viewed 787

I'm trying to get a data from a Postgres database, it keep on throwing errors on the debug mode. Have tried some many solutions like connecting through emulator proxy, it shows success but on emulator device it throws error. Have tried so many solutions including the once posted on this platform. Please I will be glad if someone can help me out.

      home: FutureBuilder(
        future: getUser(), // a previously-obtained Future<String> or null
        builder: (BuildContext context, AsyncSnapshot snapshot) {
          if (snapshot.connectionState == ConnectionState.none && snapshot.hasData == null) {
            //print('project snapshot data is: ${projectSnap.data}')
            return Container();
          }
          return ListView.builder(
            itemCount: snapshot.data.length,
            itemBuilder: (context, index) {
              return Column(
                children: <Widget>[

                ],
              );
            },
          );  
        },
      ),

  Future getUser() async {
    var result = await http.get(Uri.encodeFull('http://127.0.0.1:5000/api/register'), headers: {"Accept": "application/json"});
    print(result.body);
    return result;
  }

This Error was also logged on the console

I/flutter (18791): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (18791): The following NoSuchMethodError was thrown building FutureBuilder<dynamic>(dirty, state:
I/flutter (18791): _FutureBuilderState<dynamic>#96150):
I/flutter (18791): The getter 'length' was called on null.
I/flutter (18791): Receiver: null
I/flutter (18791): Tried calling: length
I/flutter (18791):
I/flutter (18791): The relevant error-causing widget was:
I/flutter (18791):   FutureBuilder<dynamic>
I/flutter (18791):   file:///C:/Users/Oregs/AndroidStudioProjects/TodoProject/App/todoapp/lib/main.dart:24:13
I/flutter (18791):
I/flutter (18791): When the exception was thrown, this was the stack:
I/flutter (18791): #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
I/flutter (18791): #1      MyApp.build.<anonymous closure> (package:com/main.dart:32:38)
I/flutter (18791): #2      _FutureBuilderState.build (package:flutter/src/widgets/async.dart:732:55)
I/flutter (18791): #3      StatefulElement.build (package:flutter/src/widgets/framework.dart:4619:28)
I/flutter (18791): #4      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4502:15)
I/flutter (18791): #5      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4675:11)
I/flutter (18791): #6      Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
I/flutter (18791): #7      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4481:5)
I/flutter (18791): #8      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4666:11)
I/flutter (18791): #9      ComponentElement.mount (package:flutter/src/widgets/framework.dart:4476:5)
I/flutter (18791): ...     Normal element mounting (115 frames)
I/flutter (18791): #124    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
I/flutter (18791): #125    MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5947:32)
I/flutter (18791): ...     Normal element mounting (238 frames)
I/flutter (18791): #363    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
I/flutter (18791): #364    Element.updateChild (package:flutter/src/widgets/framework.dart:3214:18)
I/flutter (18791): #365    RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1148:16)
I/flutter (18791): #366    RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1119:5)
I/flutter (18791): #367    RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:1061:17)
I/flutter (18791): #368    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2607:19)
I/flutter (18791): #369    RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1060:13)
I/flutter (18791): #370    WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:941:7)
I/flutter (18791): #371    WidgetsBinding.scheduleAttachRootWidget.<anonymous closure> (package:flutter/src/widgets/binding.dart:922:7)
I/flutter (18791): (elided 11 frames from class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)
I/flutter (18791):
I/flutter (18791): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (18791): Another exception was thrown: NoSuchMethodError: The getter 'length' was called on null.
0 Answers
Related