Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Troubleshooting Flutter App Integration with Feathers.js Server #60

Open
MrErrorSan opened this issue Mar 25, 2024 · 0 comments
Open

Troubleshooting Flutter App Integration with Feathers.js Server #60

MrErrorSan opened this issue Mar 25, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@MrErrorSan
Copy link

I am reaching out regarding a project I am currently undertaking involving the development of a Flutter app. This project necessitates real-time data integration from the server socket, which is built using Feathers.js. After extensive research, I discovered that your plugin is the sole option available on pub.dev that meets our requirements.

I diligently followed the provided documentation to integrate the plugin into our application. However, despite our efforts, we encountered difficulties in retrieving data or user information, with occasional failures in the re-authentication process.

In light of this, I would greatly appreciate it if you could spare some time to review the attached main.dart file. Your expertise in this matter would be invaluable in identifying any potential mistakes or oversights in our implementation.

import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:flutter_feathersjs/flutter_feathersjs.dart';
import 'package:socket_io_client/socket_io_client.dart' as IO;

//Using following dependencies :

// flutter_feathersjs: ^4.1.3
// flutter_slidable: ^3.0.0
// http: ^0.13.5
// logger: ^1.3.0
// socket_io_client: ^1.0.2
// username_gen: ^1.0.4

//Variables to store login data
const BASE_URL = '';
const UserName = '';
const Password = '';
const Strategy = "local";

//  Main Function
void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
}

// Configuration for App
class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'FlutterFeathersJS',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
        fontFamily: "Abel",
        scaffoldBackgroundColor: const Color(0xffF5F5F3),
      ),
      home: const MySocketData(),
    );
  }
}

// Class to get Data from socket and manage it
class MySocketData extends StatefulWidget {
  const MySocketData({Key? key}) : super(key: key);

  @override
  State<MySocketData> createState() => _MySocketDataState();
}

class _MySocketDataState extends State<MySocketData> {
  late FlutterFeathersjs flutterFeathersjs;
  late FlutterFeathersjs client;

  @override
  void initState() {
    super.initState();
    // initialization of client
    flutterFeathersjs = FlutterFeathersjs()..init(baseUrl: BASE_URL);
    // Login to server socket and get data from service
    getData();
  }

  Future<void> getData() async {
    await flutterFeathersjs.init(baseUrl: BASE_URL);
    try {
      // Authenticate
      await flutterFeathersjs
          .authenticate(
        userName: UserName,
        password: Password,
        strategy: Strategy,
      )
          .then((response) {
        log("Login Response: $response");
      }).onError((error, stackTrace) {
        log("Auth Error: $error");
        log("Auth StackTrace: $stackTrace");
      });

      log("Login Successful");

      // Re-Authenticate

      var response = await flutterFeathersjs.reAuthenticate();
      print('RE-Auth : $response');

      // Getting User

      await flutterFeathersjs.user().then((value) {
        log("User : $value");
      });

      // Connecting to service

      dynamic a = await flutterFeathersjs.service("fire-data").then((value) {
        log("Fire data: ${value.toString()}");
      });
    } catch (e) {
      // Catch errors
      log("<>- Error -<>: \n$e");
    }
  }

  // Empty Screen (Output in Terminal)
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Socket Data Service'),
      ),
      body: Center(
        child: SingleChildScrollView(
          child: Container(
            child: Text("Check Terminal..."),
          ),
        ),
      ),
    );
  }
}
@MrErrorSan MrErrorSan added the bug Something isn't working label Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants