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

Task 3 #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
Binary file added assets/fonts/GillSansC.ttf
Binary file not shown.
Binary file added assets/images/ball.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/error_ball.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/error_inner_circle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/error_outer_circle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/inner_circle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/outer_circle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/small_star.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/star.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/star_error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions docs/results/RESULT.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# Целевая платформа

[здесь вставьте платформу/платформы под которые вы разрабатывали, это поможет нам при проверке заданий]

Мобильное приложение
# Результаты

[здесь можете похвастаться, что успели реализовать или сделали что-то сверх задания]
Добавил логику для обработки пользовательского вопроса и получения ответа от API.

# Ссылки на демонстрацию работы/скриншоты

Expand Down
2 changes: 1 addition & 1 deletion ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>9.0</string>
<string>11.0</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
# platform :ios, '11.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
11 changes: 7 additions & 4 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -217,10 +217,12 @@
};
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
Expand All @@ -231,6 +233,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -340,7 +343,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -418,7 +421,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -467,7 +470,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
4 changes: 4 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
21 changes: 21 additions & 0 deletions lib/constants/app_images.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
abstract class AppImages {
AppImages._();

static const String ball = "assets/images/ball.png";

static const String ballError = "assets/images/error_ball.png";

static const String smallStar = "assets/images/small_star.png";

static const String star = "assets/images/star.png";

static const String starError = "assets/images/star_error.png";

static const String outerCircle = "assets/images/outer_circle.png";

static const String innerCircle = "assets/images/inner_circle.png";

static const String outerCircleError = "assets/images/error_outer_circle.png";

static const String innerCircleError = "assets/images/error_inner_circle.png";
}
13 changes: 8 additions & 5 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:surf_practice_magic_ball/screen/magic_ball_screen.dart';

void main() async {
Expand All @@ -14,12 +15,14 @@ class MyApp extends StatelessWidget {

@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
return ScreenUtilInit(
builder: (context, child) => MaterialApp(
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MagicBallScreen(),
),
home: const MagicBallScreen(),
);
}
}
153 changes: 151 additions & 2 deletions lib/screen/magic_ball_screen.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,159 @@
// import 'dart:convert';
// import 'dart:math';
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:surf_practice_magic_ball/constants/app_images.dart';
import 'package:surf_practice_magic_ball/theme/app_theme.dart';

class MagicBallScreen extends StatelessWidget {
class MagicBallScreen extends StatefulWidget {
const MagicBallScreen({Key? key}) : super(key: key);

@override
State<MagicBallScreen> createState() => _MagicBallScreenState();
}

class _MagicBallScreenState extends State<MagicBallScreen> {
String apiUrl = "https://eightballapi.com/api";
String currentAnswer = "";
bool isAnswerVisible = false;
bool isAnimating = false;
bool error = false;

void shakeBall() {
if (isAnimating) return; // Блокируем действия во время анимации

setState(() {
currentAnswer = "";
isAnswerVisible = false;
isAnimating = true;
});

// Выполняем GET-запрос к API для получения ответа
http.get(Uri.parse(apiUrl)).then((response) {
if (response.statusCode == 200) {
Map<String, dynamic> data = jsonDecode(response.body);
setState(() {
currentAnswer = data["reading"];
isAnswerVisible = true;
});
} else {
// В случае ошибки от API показываем сообщение об ошибке
setState(() {
currentAnswer = "";
error = true;
isAnswerVisible = true;
});
}
}).catchError((error) {
// В случае ошибки при выполнении запроса показываем сообщение об ошибке
setState(() {
currentAnswer = "";
error = true;
isAnswerVisible = true;
});
}).whenComplete(() {
// Завершаем анимацию
Future.delayed(const Duration(seconds: 3), () {
setState(() {
isAnimating = false;
isAnswerVisible = false;
});
});
});
}

@override
Widget build(BuildContext context) {
return Container();
return Scaffold(
body: Container(
width: MediaQuery.of(context).size.width,
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color.fromRGBO(16, 12, 44, 1),
Color.fromRGBO(14, 10, 36, 1),
Color.fromRGBO(1, 1, 3, 1),
],
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(
height: 200,
),
GestureDetector(
onTap: shakeBall,
child: Stack(
alignment: Alignment.center,
children: [
Image.asset(
error ? AppImages.ballError : AppImages.ball,
),
AnimatedOpacity(
duration: const Duration(
milliseconds: 300,
),
opacity: !isAnswerVisible ? 1.0 : 0,
child: Image.asset(AppImages.smallStar),
),
AnimatedOpacity(
duration: const Duration(
milliseconds: 300,
),
opacity: isAnswerVisible ? 1.0 : 0,
child: Text(
currentAnswer,
style: Theme.of(context).textTheme.ballHeader,
),
),
AnimatedOpacity(
duration: const Duration(milliseconds: 300),
opacity: !isAnswerVisible ? 1.0 : 0,
child: Image.asset(
error ? AppImages.starError : AppImages.star,
),
),
],
),
),
AnimatedOpacity(
duration: const Duration(milliseconds: 500),
opacity: !isAnswerVisible ? 1.0 : 0,
child: Stack(
alignment: Alignment.center,
children: [
Image.asset(
error ? AppImages.innerCircleError : AppImages.innerCircle,
),
Image.asset(
error ? AppImages.outerCircleError : AppImages.outerCircle,
),
],
),
),
Padding(
padding: const EdgeInsets.only(top: 100),
child: Column(
children: [
Text(
"Нажми на шар",
style: Theme.of(context).textTheme.ballCaption,
),
Text(
"или потряси телефон",
style: Theme.of(context).textTheme.ballCaption,
)
],
),
)
],
),
),
);
}
}
16 changes: 16 additions & 0 deletions lib/theme/app_theme.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

extension CustomStyles on TextTheme {
TextStyle get ballCaption => TextStyle(
color: const Color.fromRGBO(114, 114, 114, 1),
fontSize: 16.sp,
fontWeight: FontWeight.w400,
);

TextStyle get ballHeader => TextStyle(
color: Colors.white,
fontSize: 25.sp,
fontWeight: FontWeight.w400,
);
}
Loading