Compare commits
2 Commits
28db4ce298
...
d8e68f9b34
| Author | SHA1 | Date | |
|---|---|---|---|
| d8e68f9b34 | |||
| e95fb08e31 |
@@ -23,7 +23,7 @@ if (flutterVersionName == null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace "com.example.flutter_application_1"
|
namespace "com.example.gym_app"
|
||||||
compileSdk flutter.compileSdkVersion
|
compileSdk flutter.compileSdkVersion
|
||||||
ndkVersion flutter.ndkVersion
|
ndkVersion flutter.ndkVersion
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ android {
|
|||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
// 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.
|
// 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.
|
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<application
|
<application
|
||||||
android:label="flutter_application_1"
|
android:label="Example Gym App"
|
||||||
android:name="${applicationName}"
|
android:name="${applicationName}"
|
||||||
android:icon="@mipmap/ic_launcher">
|
android:icon="@mipmap/ic_launcher">
|
||||||
<activity
|
<activity
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
android:name="flutterEmbedding"
|
android:name="flutterEmbedding"
|
||||||
android:value="2" />
|
android:value="2" />
|
||||||
</application>
|
</application>
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<!-- Required to query activities that can process text, see:
|
<!-- Required to query activities that can process text, see:
|
||||||
https://developer.android.com/training/package-visibility?hl=en and
|
https://developer.android.com/training/package-visibility?hl=en and
|
||||||
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
|
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.example.flutter_application_1
|
package com.example.gym_app
|
||||||
|
|
||||||
import io.flutter.embedding.android.FlutterActivity
|
import io.flutter.embedding.android.FlutterActivity
|
||||||
|
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
|
import 'dart:convert';
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:gymlink_module_web/main_mobile.dart';
|
import 'package:gymlink_module_web/main_mobile.dart';
|
||||||
import 'package:gymlink_module_web/providers/main.dart';
|
import 'package:gymlink_module_web/providers/main.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
@@ -71,11 +73,50 @@ class _ExamplePageState extends State<ExamplePage> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
Future.microtask(
|
// Future.microtask(
|
||||||
() => context.read<GymLinkProvider>().onTokenReceived('token123'));
|
// () => context.read<GymLinkProvider>().onTokenReceived('token123'));
|
||||||
Future.microtask(() => context
|
Future.microtask(() => context
|
||||||
.read<GymLinkProvider>()
|
.read<GymLinkProvider>()
|
||||||
.setTheme(ThemeData.light(useMaterial3: true)));
|
.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
|
@override
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ class GymLinkProvider with ChangeNotifier {
|
|||||||
bool get isLoading => _isLoading;
|
bool get isLoading => _isLoading;
|
||||||
bool _blackTheme = false;
|
bool _blackTheme = false;
|
||||||
bool get blackTheme => _blackTheme;
|
bool get blackTheme => _blackTheme;
|
||||||
|
String _token = '';
|
||||||
|
String get token => _token;
|
||||||
ThemeData _theme = myTheme;
|
ThemeData _theme = myTheme;
|
||||||
ThemeData get theme => _theme;
|
ThemeData get theme => _theme;
|
||||||
void Function() _onError = () => {};
|
void Function() _onError = () => {};
|
||||||
@@ -13,13 +15,16 @@ class GymLinkProvider with ChangeNotifier {
|
|||||||
void Function() get onError => _onError;
|
void Function() get onError => _onError;
|
||||||
|
|
||||||
void onTokenReceived(String token) {
|
void onTokenReceived(String token) {
|
||||||
if (token == 'token123') {
|
_token = token;
|
||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
} else {
|
// if (token == 'token123') {
|
||||||
_isLoading = true;
|
// _isLoading = false;
|
||||||
notifyListeners();
|
// notifyListeners();
|
||||||
}
|
// } else {
|
||||||
|
// _isLoading = true;
|
||||||
|
// notifyListeners();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void changeTheme(int color) {
|
void changeTheme(int color) {
|
||||||
|
|||||||
@@ -7,10 +7,35 @@
|
|||||||
};
|
};
|
||||||
let appState = window._appState;
|
let appState = window._appState;
|
||||||
|
|
||||||
let btn = document.getElementById('token');
|
function getToken() {
|
||||||
btn.addEventListener('click', function () {
|
fetch(
|
||||||
appState.onTokenReceived('token123');
|
'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', getToken);
|
||||||
|
|
||||||
let colorChangeBtnRed = document.getElementById('colorChangeBtnRed');
|
let colorChangeBtnRed = document.getElementById('colorChangeBtnRed');
|
||||||
colorChangeBtnRed.addEventListener('click', function () {
|
colorChangeBtnRed.addEventListener('click', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user