import 'dart:async'; import 'package:flutter/material.dart'; import 'package:imagini/api/cookie_client/cookie_client.dart' if (dart.library.html) 'package:imagini/api/cookie_client/browser_cookie_client.dart' if (dart.library.io) 'package:imagini/api/cookie_client/io_cookie_client.dart'; import 'package:imagini/core/storage_client/base_storage_client.dart'; import 'package:graphql_flutter/graphql_flutter.dart'; import 'package:imagini/graphql/imagini_graphql.dart'; class APIProvider{ static const String _GRAPHQL_ENDPOINT = "/query"; BaseStorageClient _storage; GraphQLClient _client; HttpLink httpLink; APIProvider(BaseStorageClient storage) { _storage = storage; init(); } Future init() async { String _server = await _storage.get("server"); httpLink = HttpLink(_server + _GRAPHQL_ENDPOINT, httpClient: getCookieClient(_storage), ); _client = GraphQLClient( cache: GraphQLCache(), link: httpLink, ); } Future login( String username, String password, String server, ) async { assert( (username != null && password != null && server != null) ); // Initialize Connection await _storage.set("server", server); await init(); QueryResult response = await _client.query( QueryOptions( document: LoginQuery().document, variables: { "user": username, "password": password }, ) ); return response; } Image getImage(String fileName) { // TODO: Get headers & Server String fullURL = fileName; return new Image.network( fullURL, headers: {}, fit: BoxFit.contain, ); } Future me() async { QueryResult response = await _client.query( QueryOptions( document: MeQuery().document, ) ); return response; } Future mediaItems() async { QueryResult response = await _client.query( QueryOptions( document: MediaItemsQuery().document, ) ); return response; } void dispose() {} }