Compare commits

..

2 Commits

Author SHA1 Message Date
d8e68f9b34 Add: get token from api 2024-05-22 00:41:44 +03:00
e95fb08e31 Rename: application name 2024-05-22 00:40:48 +03:00
6 changed files with 88 additions and 16 deletions

View File

@@ -23,7 +23,7 @@ if (flutterVersionName == null) {
}
android {
namespace "com.example.flutter_application_1"
namespace "com.example.gym_app"
compileSdk flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
@@ -42,7 +42,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.flutter_application_1"
applicationId "com.example.gym_app"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion 21

View File

@@ -1,6 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:label="flutter_application_1"
android:label="Example Gym App"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
@@ -30,6 +30,7 @@
android:name="flutterEmbedding"
android:value="2" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<!-- Required to query activities that can process text, see:
https://developer.android.com/training/package-visibility?hl=en and
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.

View File

@@ -1,4 +1,4 @@
package com.example.flutter_application_1
package com.example.gym_app
import io.flutter.embedding.android.FlutterActivity

View File

@@ -1,8 +1,10 @@
import 'dart:convert';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:gymlink_module_web/main_mobile.dart';
import 'package:gymlink_module_web/providers/main.dart';
import 'package:http/http.dart' as http;
import 'package:provider/provider.dart';
void main() {
@@ -71,11 +73,50 @@ class _ExamplePageState extends State<ExamplePage> {
@override
void initState() {
super.initState();
Future.microtask(
() => context.read<GymLinkProvider>().onTokenReceived('token123'));
// Future.microtask(
// () => context.read<GymLinkProvider>().onTokenReceived('token123'));
Future.microtask(() => context
.read<GymLinkProvider>()
.setTheme(ThemeData.light(useMaterial3: true)));
Future.microtask(() => context.read<GymLinkProvider>().setOnError(() {
const snackBar = SnackBar(
content: Text('Ошибка подключения'),
duration: Duration(seconds: 3), // Длительность отображения Snackbar
behavior: SnackBarBehavior
.fixed, // Поведение Snackbar (fixed или floating)
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
Future.delayed(const Duration(seconds: 3))
.then((value) => _setToken());
}));
Future.microtask(() async {
await _setToken();
});
}
Future<void> _setToken() async {
final token = await _getToken();
if (token != '') {
context.read<GymLinkProvider>().onTokenReceived(token);
} else {
context.read<GymLinkProvider>().onError();
}
}
Future<String> _getToken() async {
var url =
Uri.http('gymlink.freemyip.com:8080', 'api/auth/authorize_client');
var response = await http.post(url, body: {
'GymKey': 'eeb42dcb-8e5b-4f21-825a-3fc7ada43445',
'id': '123'
}); // Just testing token
var decodedBody = jsonDecode(response.body) as Map;
if (decodedBody['payload'] == null) {
return '';
}
return decodedBody['payload']['token'];
}
@override

View File

@@ -6,6 +6,8 @@ class GymLinkProvider with ChangeNotifier {
bool get isLoading => _isLoading;
bool _blackTheme = false;
bool get blackTheme => _blackTheme;
String _token = '';
String get token => _token;
ThemeData _theme = myTheme;
ThemeData get theme => _theme;
void Function() _onError = () => {};
@@ -13,13 +15,16 @@ class GymLinkProvider with ChangeNotifier {
void Function() get onError => _onError;
void onTokenReceived(String token) {
if (token == 'token123') {
_isLoading = false;
notifyListeners();
} else {
_isLoading = true;
notifyListeners();
}
_token = token;
_isLoading = false;
notifyListeners();
// if (token == 'token123') {
// _isLoading = false;
// notifyListeners();
// } else {
// _isLoading = true;
// notifyListeners();
// }
}
void changeTheme(int color) {

View File

@@ -7,10 +7,35 @@
};
let appState = window._appState;
function getToken() {
fetch(
'http://gymlink.freemyip.com:8080/api/auth/authorize_client',
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
GymKey: 'eeb42dcb-8e5b-4f21-825a-3fc7ada43445', // Just testing token
id: '123',
}),
}
)
.then(res => res.json())
.catch(e => {
console.log(e);
setTimeout(getToken, 1000);
})
.then(data => {
if (data.payload)
appState.onTokenReceived(data.payload.token);
else {
console.log(data);
setTimeout(getToken, 1000);
}
});
}
let btn = document.getElementById('token');
btn.addEventListener('click', function () {
appState.onTokenReceived('token123');
});
btn.addEventListener('click', getToken);
let colorChangeBtnRed = document.getElementById('colorChangeBtnRed');
colorChangeBtnRed.addEventListener('click', function () {