From 0efbd55833b312e561319bd6ddba7b56dc6ca0aa Mon Sep 17 00:00:00 2001 From: kotelnikov-aa Date: Thu, 16 Jun 2022 08:21:14 +0700 Subject: [PATCH 1/2] course_project/kotelnikov MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Курсовой проект. API сервиса Кинопоиск --- flutter_course/.gitignore | 46 ++++ flutter_course/.metadata | 30 +++ flutter_course/README.md | 16 ++ flutter_course/analysis_options.yaml | 29 +++ flutter_course/android/.gitignore | 13 ++ flutter_course/android/app/build.gradle | 71 ++++++ .../android/app/src/debug/AndroidManifest.xml | 8 + .../android/app/src/main/AndroidManifest.xml | 34 +++ .../ru/rtkit/flutter_first/MainActivity.kt | 6 + .../res/drawable-v21/launch_background.xml | 12 ++ .../main/res/drawable/launch_background.xml | 12 ++ .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 544 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 442 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 721 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 1031 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 1443 bytes .../app/src/main/res/values-night/styles.xml | 18 ++ .../app/src/main/res/values/styles.xml | 18 ++ .../app/src/profile/AndroidManifest.xml | 8 + flutter_course/android/build.gradle | 31 +++ flutter_course/android/gradle.properties | 3 + .../gradle/wrapper/gradle-wrapper.properties | 6 + flutter_course/android/settings.gradle | 11 + flutter_course/lib/api_service.dart | 57 +++++ flutter_course/lib/bloc/movie_bloc.dart | 116 ++++++++++ flutter_course/lib/enums.dart | 15 ++ flutter_course/lib/main.dart | 115 ++++++++++ flutter_course/lib/models/api_model.dart | 21 ++ flutter_course/lib/models/comment_model.dart | 22 ++ flutter_course/lib/models/movie_model.dart | 176 +++++++++++++++ flutter_course/lib/models/post_model.dart | 19 ++ flutter_course/lib/models/review_model.dart | 55 +++++ .../lib/screens/favorite_screen.dart | 202 ++++++++++++++++++ flutter_course/lib/screens/movie_screen.dart | 202 ++++++++++++++++++ .../lib/screens/review_detail_screen.dart | 125 +++++++++++ flutter_course/lib/screens/review_screen.dart | 151 +++++++++++++ flutter_course/lib/theme/navigator_bar.dart | 38 ++++ flutter_course/lib/theme/theme.dart | 42 ++++ flutter_course/pubspec.yaml | 108 ++++++++++ 39 files changed, 1836 insertions(+) create mode 100644 flutter_course/.gitignore create mode 100644 flutter_course/.metadata create mode 100644 flutter_course/README.md create mode 100644 flutter_course/analysis_options.yaml create mode 100644 flutter_course/android/.gitignore create mode 100644 flutter_course/android/app/build.gradle create mode 100644 flutter_course/android/app/src/debug/AndroidManifest.xml create mode 100644 flutter_course/android/app/src/main/AndroidManifest.xml create mode 100644 flutter_course/android/app/src/main/kotlin/ru/rtkit/flutter_first/MainActivity.kt create mode 100644 flutter_course/android/app/src/main/res/drawable-v21/launch_background.xml create mode 100644 flutter_course/android/app/src/main/res/drawable/launch_background.xml create mode 100644 flutter_course/android/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 flutter_course/android/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 flutter_course/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 flutter_course/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 flutter_course/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 flutter_course/android/app/src/main/res/values-night/styles.xml create mode 100644 flutter_course/android/app/src/main/res/values/styles.xml create mode 100644 flutter_course/android/app/src/profile/AndroidManifest.xml create mode 100644 flutter_course/android/build.gradle create mode 100644 flutter_course/android/gradle.properties create mode 100644 flutter_course/android/gradle/wrapper/gradle-wrapper.properties create mode 100644 flutter_course/android/settings.gradle create mode 100644 flutter_course/lib/api_service.dart create mode 100644 flutter_course/lib/bloc/movie_bloc.dart create mode 100644 flutter_course/lib/enums.dart create mode 100644 flutter_course/lib/main.dart create mode 100644 flutter_course/lib/models/api_model.dart create mode 100644 flutter_course/lib/models/comment_model.dart create mode 100644 flutter_course/lib/models/movie_model.dart create mode 100644 flutter_course/lib/models/post_model.dart create mode 100644 flutter_course/lib/models/review_model.dart create mode 100644 flutter_course/lib/screens/favorite_screen.dart create mode 100644 flutter_course/lib/screens/movie_screen.dart create mode 100644 flutter_course/lib/screens/review_detail_screen.dart create mode 100644 flutter_course/lib/screens/review_screen.dart create mode 100644 flutter_course/lib/theme/navigator_bar.dart create mode 100644 flutter_course/lib/theme/theme.dart create mode 100644 flutter_course/pubspec.yaml diff --git a/flutter_course/.gitignore b/flutter_course/.gitignore new file mode 100644 index 0000000..0fa6b67 --- /dev/null +++ b/flutter_course/.gitignore @@ -0,0 +1,46 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.packages +.pub-cache/ +.pub/ +/build/ + +# Web related +lib/generated_plugin_registrant.dart + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release diff --git a/flutter_course/.metadata b/flutter_course/.metadata new file mode 100644 index 0000000..6d6bd83 --- /dev/null +++ b/flutter_course/.metadata @@ -0,0 +1,30 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled. + +version: + revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268 + channel: stable + +project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268 + base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268 + - platform: android + create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268 + base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268 + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/flutter_course/README.md b/flutter_course/README.md new file mode 100644 index 0000000..adc5de3 --- /dev/null +++ b/flutter_course/README.md @@ -0,0 +1,16 @@ +# flutter_first + +Course project of Epic school + +## Getting Started + +This project is a starting point for a Flutter application. + +A few resources to get you started if this is your first Flutter project: + +- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) +- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) + +For help getting started with Flutter development, view the +[online documentation](https://docs.flutter.dev/), which offers tutorials, +samples, guidance on mobile development, and a full API reference. diff --git a/flutter_course/analysis_options.yaml b/flutter_course/analysis_options.yaml new file mode 100644 index 0000000..61b6c4d --- /dev/null +++ b/flutter_course/analysis_options.yaml @@ -0,0 +1,29 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at + # https://dart-lang.github.io/linter/lints/index.html. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/flutter_course/android/.gitignore b/flutter_course/android/.gitignore new file mode 100644 index 0000000..6f56801 --- /dev/null +++ b/flutter_course/android/.gitignore @@ -0,0 +1,13 @@ +gradle-wrapper.jar +/.gradle +/captures/ +/gradlew +/gradlew.bat +/local.properties +GeneratedPluginRegistrant.java + +# Remember to never publicly share your keystore. +# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app +key.properties +**/*.keystore +**/*.jks diff --git a/flutter_course/android/app/build.gradle b/flutter_course/android/app/build.gradle new file mode 100644 index 0000000..2405c65 --- /dev/null +++ b/flutter_course/android/app/build.gradle @@ -0,0 +1,71 @@ +def localProperties = new Properties() +def localPropertiesFile = rootProject.file('local.properties') +if (localPropertiesFile.exists()) { + localPropertiesFile.withReader('UTF-8') { reader -> + localProperties.load(reader) + } +} + +def flutterRoot = localProperties.getProperty('flutter.sdk') +if (flutterRoot == null) { + throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") +} + +def flutterVersionCode = localProperties.getProperty('flutter.versionCode') +if (flutterVersionCode == null) { + flutterVersionCode = '1' +} + +def flutterVersionName = localProperties.getProperty('flutter.versionName') +if (flutterVersionName == null) { + flutterVersionName = '1.0' +} + +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" + +android { + compileSdkVersion flutter.compileSdkVersion + ndkVersion flutter.ndkVersion + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = '1.8' + } + + sourceSets { + main.java.srcDirs += 'src/main/kotlin' + } + + defaultConfig { + // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). + applicationId "ru.rtkit.flutter_first" + // You can update the following values to match your application needs. + // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration. + minSdkVersion flutter.minSdkVersion + targetSdkVersion flutter.targetSdkVersion + versionCode flutterVersionCode.toInteger() + versionName flutterVersionName + } + + buildTypes { + release { + // TODO: Add your own signing config for the release build. + // Signing with the debug keys for now, so `flutter run --release` works. + signingConfig signingConfigs.debug + } + } +} + +flutter { + source '../..' +} + +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" +} diff --git a/flutter_course/android/app/src/debug/AndroidManifest.xml b/flutter_course/android/app/src/debug/AndroidManifest.xml new file mode 100644 index 0000000..d5f50c9 --- /dev/null +++ b/flutter_course/android/app/src/debug/AndroidManifest.xml @@ -0,0 +1,8 @@ + + + + diff --git a/flutter_course/android/app/src/main/AndroidManifest.xml b/flutter_course/android/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..ac9c217 --- /dev/null +++ b/flutter_course/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + diff --git a/flutter_course/android/app/src/main/kotlin/ru/rtkit/flutter_first/MainActivity.kt b/flutter_course/android/app/src/main/kotlin/ru/rtkit/flutter_first/MainActivity.kt new file mode 100644 index 0000000..f48de95 --- /dev/null +++ b/flutter_course/android/app/src/main/kotlin/ru/rtkit/flutter_first/MainActivity.kt @@ -0,0 +1,6 @@ +package ru.rtkit.flutter_first + +import io.flutter.embedding.android.FlutterActivity + +class MainActivity: FlutterActivity() { +} diff --git a/flutter_course/android/app/src/main/res/drawable-v21/launch_background.xml b/flutter_course/android/app/src/main/res/drawable-v21/launch_background.xml new file mode 100644 index 0000000..f74085f --- /dev/null +++ b/flutter_course/android/app/src/main/res/drawable-v21/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/flutter_course/android/app/src/main/res/drawable/launch_background.xml b/flutter_course/android/app/src/main/res/drawable/launch_background.xml new file mode 100644 index 0000000..304732f --- /dev/null +++ b/flutter_course/android/app/src/main/res/drawable/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/flutter_course/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/flutter_course/android/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..db77bb4b7b0906d62b1847e87f15cdcacf6a4f29 GIT binary patch literal 544 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY3?!3`olAj~WQl7;NpOBzNqJ&XDuZK6ep0G} zXKrG8YEWuoN@d~6R2!h8bpbvhu0Wd6uZuB!w&u2PAxD2eNXD>P5D~Wn-+_Wa#27Xc zC?Zj|6r#X(-D3u$NCt}(Ms06KgJ4FxJVv{GM)!I~&n8Bnc94O7-Hd)cjDZswgC;Qs zO=b+9!WcT8F?0rF7!Uys2bs@gozCP?z~o%U|N3vA*22NaGQG zlg@K`O_XuxvZ&Ks^m&R!`&1=spLvfx7oGDKDwpwW`#iqdw@AL`7MR}m`rwr|mZgU`8P7SBkL78fFf!WnuYWm$5Z0 zNXhDbCv&49sM544K|?c)WrFfiZvCi9h0O)B3Pgg&ebxsLQ05GG~ AQ2+n{ literal 0 HcmV?d00001 diff --git a/flutter_course/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/flutter_course/android/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..17987b79bb8a35cc66c3c1fd44f5a5526c1b78be GIT binary patch literal 442 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA3?vioaBc-sk|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*D5Xx&nMcT!A!W`0S9QKQy;}1Cl^CgaH=;G9cpY;r$Q>i*pfB zP2drbID<_#qf;rPZx^FqH)F_D#*k@@q03KywUtLX8Ua?`H+NMzkczFPK3lFz@i_kW%1NOn0|D2I9n9wzH8m|-tHjsw|9>@K=iMBhxvkv6m8Y-l zytQ?X=U+MF$@3 zt`~i=@j|6y)RWMK--}M|=T`o&^Ni>IoWKHEbBXz7?A@mgWoL>!*SXo`SZH-*HSdS+ yn*9;$7;m`l>wYBC5bq;=U}IMqLzqbYCidGC!)_gkIk_C@Uy!y&wkt5C($~2D>~)O*cj@FGjOCM)M>_ixfudOh)?xMu#Fs z#}Y=@YDTwOM)x{K_j*Q;dPdJ?Mz0n|pLRx{4n|)f>SXlmV)XB04CrSJn#dS5nK2lM zrZ9#~WelCp7&e13Y$jvaEXHskn$2V!!DN-nWS__6T*l;H&Fopn?A6HZ-6WRLFP=R` zqG+CE#d4|IbyAI+rJJ`&x9*T`+a=p|0O(+s{UBcyZdkhj=yS1>AirP+0R;mf2uMgM zC}@~JfByORAh4SyRgi&!(cja>F(l*O+nd+@4m$|6K6KDn_&uvCpV23&>G9HJp{xgg zoq1^2_p9@|WEo z*X_Uko@K)qYYv~>43eQGMdbiGbo>E~Q& zrYBH{QP^@Sti!`2)uG{irBBq@y*$B zi#&(U-*=fp74j)RyIw49+0MRPMRU)+a2r*PJ$L5roHt2$UjExCTZSbq%V!HeS7J$N zdG@vOZB4v_lF7Plrx+hxo7(fCV&}fHq)$ literal 0 HcmV?d00001 diff --git a/flutter_course/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/flutter_course/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..d5f1c8d34e7a88e3f88bea192c3a370d44689c3c GIT binary patch literal 1031 zcmeAS@N?(olHy`uVBq!ia0vp^6F``Q8Ax83A=Cw=BuiW)N`mv#O3D+9QW+dm@{>{( zJaZG%Q-e|yQz{EjrrIztFa`(sgt!6~Yi|1%a`XoT0ojZ}lNrNjb9xjc(B0U1_% zz5^97Xt*%oq$rQy4?0GKNfJ44uvxI)gC`h-NZ|&0-7(qS@?b!5r36oQ}zyZrNO3 zMO=Or+<~>+A&uN&E!^Sl+>xE!QC-|oJv`ApDhqC^EWD|@=#J`=d#Xzxs4ah}w&Jnc z$|q_opQ^2TrnVZ0o~wh<3t%W&flvYGe#$xqda2bR_R zvPYgMcHgjZ5nSA^lJr%;<&0do;O^tDDh~=pIxA#coaCY>&N%M2^tq^U%3DB@ynvKo}b?yu-bFc-u0JHzced$sg7S3zqI(2 z#Km{dPr7I=pQ5>FuK#)QwK?Y`E`B?nP+}U)I#c1+FM*1kNvWG|a(TpksZQ3B@sD~b zpQ2)*V*TdwjFOtHvV|;OsiDqHi=6%)o4b!)x$)%9pGTsE z-JL={-Ffv+T87W(Xpooq<`r*VzWQcgBN$$`u}f>-ZQI1BB8ykN*=e4rIsJx9>z}*o zo~|9I;xof literal 0 HcmV?d00001 diff --git a/flutter_course/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/flutter_course/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..4d6372eebdb28e45604e46eeda8dd24651419bc0 GIT binary patch literal 1443 zcmb`G{WsKk6vsdJTdFg%tJav9_E4vzrOaqkWF|A724Nly!y+?N9`YV6wZ}5(X(D_N(?!*n3`|_r0Hc?=PQw&*vnU?QTFY zB_MsH|!j$PP;I}?dppoE_gA(4uc!jV&0!l7_;&p2^pxNo>PEcNJv za5_RT$o2Mf!<+r?&EbHH6nMoTsDOa;mN(wv8RNsHpG)`^ymG-S5By8=l9iVXzN_eG%Xg2@Xeq76tTZ*dGh~Lo9vl;Zfs+W#BydUw zCkZ$o1LqWQO$FC9aKlLl*7x9^0q%0}$OMlp@Kk_jHXOjofdePND+j!A{q!8~Jn+s3 z?~~w@4?egS02}8NuulUA=L~QQfm;MzCGd)XhiftT;+zFO&JVyp2mBww?;QByS_1w! zrQlx%{^cMj0|Bo1FjwY@Q8?Hx0cIPF*@-ZRFpPc#bBw{5@tD(5%sClzIfl8WU~V#u zm5Q;_F!wa$BSpqhN>W@2De?TKWR*!ujY;Yylk_X5#~V!L*Gw~;$%4Q8~Mad z@`-kG?yb$a9cHIApZDVZ^U6Xkp<*4rU82O7%}0jjHlK{id@?-wpN*fCHXyXh(bLt* zPc}H-x0e4E&nQ>y%B-(EL=9}RyC%MyX=upHuFhAk&MLbsF0LP-q`XnH78@fT+pKPW zu72MW`|?8ht^tz$iC}ZwLp4tB;Q49K!QCF3@!iB1qOI=?w z7In!}F~ij(18UYUjnbmC!qKhPo%24?8U1x{7o(+?^Zu0Hx81|FuS?bJ0jgBhEMzf< zCgUq7r2OCB(`XkKcN-TL>u5y#dD6D!)5W?`O5)V^>jb)P)GBdy%t$uUMpf$SNV31$ zb||OojAbvMP?T@$h_ZiFLFVHDmbyMhJF|-_)HX3%m=CDI+ID$0^C>kzxprBW)hw(v zr!Gmda);ICoQyhV_oP5+C%?jcG8v+D@9f?Dk*!BxY}dazmrT@64UrP3hlslANK)bq z$67n83eh}OeW&SV@HG95P|bjfqJ7gw$e+`Hxo!4cx`jdK1bJ>YDSpGKLPZ^1cv$ek zIB?0S<#tX?SJCLWdMd{-ME?$hc7A$zBOdIJ)4!KcAwb=VMov)nK;9z>x~rfT1>dS+ zZ6#`2v@`jgbqq)P22H)Tx2CpmM^o1$B+xT6`(v%5xJ(?j#>Q$+rx_R|7TzDZe{J6q zG1*EcU%tE?!kO%^M;3aM6JN*LAKUVb^xz8-Pxo#jR5(-KBeLJvA@-gxNHx0M-ZJLl z;#JwQoh~9V?`UVo#}{6ka@II>++D@%KqGpMdlQ}?9E*wFcf5(#XQnP$Dk5~%iX^>f z%$y;?M0BLp{O3a(-4A?ewryHrrD%cx#Q^%KY1H zNre$ve+vceSLZcNY4U(RBX&)oZn*Py()h)XkE?PL$!bNb{N5FVI2Y%LKEm%yvpyTP z(1P?z~7YxD~Rf<(a@_y` literal 0 HcmV?d00001 diff --git a/flutter_course/android/app/src/main/res/values-night/styles.xml b/flutter_course/android/app/src/main/res/values-night/styles.xml new file mode 100644 index 0000000..06952be --- /dev/null +++ b/flutter_course/android/app/src/main/res/values-night/styles.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/flutter_course/android/app/src/main/res/values/styles.xml b/flutter_course/android/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..cb1ef88 --- /dev/null +++ b/flutter_course/android/app/src/main/res/values/styles.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/flutter_course/android/app/src/profile/AndroidManifest.xml b/flutter_course/android/app/src/profile/AndroidManifest.xml new file mode 100644 index 0000000..d5f50c9 --- /dev/null +++ b/flutter_course/android/app/src/profile/AndroidManifest.xml @@ -0,0 +1,8 @@ + + + + diff --git a/flutter_course/android/build.gradle b/flutter_course/android/build.gradle new file mode 100644 index 0000000..83ae220 --- /dev/null +++ b/flutter_course/android/build.gradle @@ -0,0 +1,31 @@ +buildscript { + ext.kotlin_version = '1.6.10' + repositories { + google() + mavenCentral() + } + + dependencies { + classpath 'com.android.tools.build:gradle:7.1.2' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +allprojects { + repositories { + google() + mavenCentral() + } +} + +rootProject.buildDir = '../build' +subprojects { + project.buildDir = "${rootProject.buildDir}/${project.name}" +} +subprojects { + project.evaluationDependsOn(':app') +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/flutter_course/android/gradle.properties b/flutter_course/android/gradle.properties new file mode 100644 index 0000000..94adc3a --- /dev/null +++ b/flutter_course/android/gradle.properties @@ -0,0 +1,3 @@ +org.gradle.jvmargs=-Xmx1536M +android.useAndroidX=true +android.enableJetifier=true diff --git a/flutter_course/android/gradle/wrapper/gradle-wrapper.properties b/flutter_course/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..cc5527d --- /dev/null +++ b/flutter_course/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Fri Jun 23 08:50:38 CEST 2017 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip diff --git a/flutter_course/android/settings.gradle b/flutter_course/android/settings.gradle new file mode 100644 index 0000000..44e62bc --- /dev/null +++ b/flutter_course/android/settings.gradle @@ -0,0 +1,11 @@ +include ':app' + +def localPropertiesFile = new File(rootProject.projectDir, "local.properties") +def properties = new Properties() + +assert localPropertiesFile.exists() +localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } + +def flutterSdkPath = properties.getProperty("flutter.sdk") +assert flutterSdkPath != null, "flutter.sdk not set in local.properties" +apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" diff --git a/flutter_course/lib/api_service.dart b/flutter_course/lib/api_service.dart new file mode 100644 index 0000000..b5ffbc7 --- /dev/null +++ b/flutter_course/lib/api_service.dart @@ -0,0 +1,57 @@ + +import 'package:dio/dio.dart'; +import 'models/movie_model.dart'; +import 'models/review_model.dart'; +import 'models/api_model.dart'; + + +const _baseUrl = 'https://api.kinopoisk.dev'; +const _apiKey = 'ZQQ8GMN-TN54SGK-NB3MKEC-ZKB8V06'; + +abstract class ApiService { + Future?, Failure>> getMovies(); + Future?, Failure>> getReviews(int movieId); +} + + + +class ApiServiceDio implements ApiService { + static final ApiServiceDio _instance = ApiServiceDio._(); + + ApiServiceDio._(); + + static ApiServiceDio get instance => _instance; + + final Dio dio = Dio()..options.baseUrl = _baseUrl; + + @override + Future?, Failure>> getMovies() async { + try { + final response = await dio.get('/movie?field=rating.kp&search=5-10&field=year&search=2021-2022&field=typeNumber&search=1&sortField=year&sortType=1&sortField=votes.imdb&sortType=-1&token=$_apiKey'); + + final list = response.data['docs'] as List; + + final models = list.map((e) => Docs.fromJson(e)); + + return ApiModel.success(models.toList()); + } catch (e) { + return ApiModel.error(Failure()); + } + } + + @override + Future?, Failure>> getReviews(int movieId) async { + try { + final response = await dio.get('/review?field=movieId&search=$movieId&&token=$_apiKey'); + + final list = response.data['docs'] as List; + + final models = list.map((e) => ReviewDocs.fromJson(e)); + + return ApiModel.success(models.toList()); + } catch (e) { + return ApiModel.error(Failure()); + } + } + +} diff --git a/flutter_course/lib/bloc/movie_bloc.dart b/flutter_course/lib/bloc/movie_bloc.dart new file mode 100644 index 0000000..b9651b9 --- /dev/null +++ b/flutter_course/lib/bloc/movie_bloc.dart @@ -0,0 +1,116 @@ +import 'package:bloc/bloc.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +import '../api_service.dart'; + +abstract class MovieEvent {} + +class LoadMovieEvent extends MovieEvent {} + +class AddToBookmarkEvent extends MovieEvent { + final int movieId; + + AddToBookmarkEvent(this.movieId); +} + +class DeleteFromBookmarkEvent extends MovieEvent { + final int movieId; + + DeleteFromBookmarkEvent(this.movieId); +} + + +abstract class MovieState {} + +class MovieInitialState extends MovieState {} + +class MovieLoadingState extends MovieState {} + +class MovieErrorState extends MovieState { + final String message; + + MovieErrorState(this.message); +} + +class MovieLoadedState extends MovieState { + MovieLoadedState({ + this.movies = const [], + this.favoritesId = const {}, + }); + + final List? movies; + Set favoritesId = {}; + + MovieLoadedState copyWith({ + List? movies, + Set? favoritesId, + + }) { + return MovieLoadedState( + movies: movies ?? this.movies, + favoritesId: favoritesId ?? this.favoritesId, + ); + } +} + +Set toSet(Set strings) { + return strings.fold>({}, (previousValue, value) { + final parsed = int.tryParse(value); + if (parsed != null) { + previousValue.add(parsed); + } + return previousValue; + }); +} + +class MovieBloc extends Bloc { + MovieBloc({ + required ApiService service, + required SharedPreferences storage, + }) : super(MovieInitialState()) { + on(( + LoadMovieEvent event, + Emitter emit, + ) async { + emit(MovieLoadingState()); + try { + final movies = await service.getMovies(); + + final Set favorites = toSet(Set.of((storage.getString('favorites') ?? '').split(';'))); + + + emit(MovieLoadedState( + movies: movies.result!, + favoritesId: favorites, + )); + } catch (e) { + emit(MovieErrorState(e.toString())); + } + }); + + on(( + AddToBookmarkEvent event, + Emitter emit, + ) async { + if (state is MovieLoadedState) { + Set next = Set.from((state as MovieLoadedState).favoritesId); + next.add(event.movieId); + await storage.setString('favorites', next.join(';')); + emit((state as MovieLoadedState).copyWith(favoritesId: next)); + } + }); + + on(( + DeleteFromBookmarkEvent event, + Emitter emit, + ) async { + if (state is MovieLoadedState) { + Set next = Set.from((state as MovieLoadedState).favoritesId); + next.remove(event.movieId); + + await storage.setString('favorites', next.join(';')); + emit((state as MovieLoadedState).copyWith(favoritesId: next)); + } + }); + } +} diff --git a/flutter_course/lib/enums.dart b/flutter_course/lib/enums.dart new file mode 100644 index 0000000..5e9e35d --- /dev/null +++ b/flutter_course/lib/enums.dart @@ -0,0 +1,15 @@ +enum ContentState { + initial, + loading, + success, + empty, + failure, +} + +enum ReviewState { + initial, + loading, + success, + empty, + failure, +} diff --git a/flutter_course/lib/main.dart b/flutter_course/lib/main.dart new file mode 100644 index 0000000..aa2b418 --- /dev/null +++ b/flutter_course/lib/main.dart @@ -0,0 +1,115 @@ +import 'package:flutter/material.dart'; +import 'package:get_it/get_it.dart'; +import 'package:provider/provider.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import 'api_service.dart'; +import 'bloc/movie_bloc.dart'; +import 'screens/movie_screen.dart'; +import 'theme/theme.dart'; + + + +void main() async { + WidgetsFlutterBinding.ensureInitialized(); + final storage = await SharedPreferences.getInstance(); + + final service = ApiServiceDio.instance; + + GetIt.I.registerSingleton( + MovieBloc( + storage: storage, + service: service, + )..add(LoadMovieEvent()), + ); + + + runApp( + MultiProvider( + providers: [ + ChangeNotifierProvider( + create: (context) => ThemeState(storage), + ) + ], + child: const App(), + ), + ); +} + + +class App extends StatelessWidget { + const App({Key? key}) : super(key: key); + + + @override + Widget build(BuildContext context) { + return Consumer(builder: ((context, state, child) { + + return MaterialApp( + navigatorKey: navKey, + themeMode: state.theme, + debugShowCheckedModeBanner: false, + theme: ThemeData( + appBarTheme: AppBarTheme( + backgroundColor: Colors.white, + elevation: 0, + titleTextStyle: TextStyle( + color: Colors.black.withOpacity(0.95), + fontSize: 18.0, + ), + ), + iconTheme: const IconThemeData( + color: Colors.red + ), + dividerTheme: const DividerThemeData( + color: Colors.black + ), + textTheme: TextTheme( + headline3: TextStyle( + color: Colors.black.withOpacity(0.95), + ), + ), + scaffoldBackgroundColor: const Color.fromRGBO(244, 244, 244, 1.0), + ), + darkTheme: ThemeData( + appBarTheme: AppBarTheme( + backgroundColor: Colors.black, + elevation: 0, + titleTextStyle: TextStyle( + color: Colors.white.withOpacity(0.95), + fontSize: 18.0, + ), + ), + iconTheme: const IconThemeData( + color: Colors.white + ), + dividerTheme: const DividerThemeData( + color: Colors.white + ), + textTheme: TextTheme( + headline3: TextStyle( + color: Colors.white.withOpacity(0.95), + ), + headline6: TextStyle( + color: Colors.white.withOpacity(0.95), + ), + subtitle1: TextStyle( + color: Colors.white.withOpacity(0.95), + ), + ), + scaffoldBackgroundColor: const Color.fromRGBO(11, 11, 15, 1.0), + switchTheme: SwitchThemeData( + thumbColor: MaterialStateProperty.all(Colors.white12), + trackColor: MaterialStateProperty.all(Colors.white), + ), + ), + home: const MovieScreen(), + ); + })); + } +} + + + + + + diff --git a/flutter_course/lib/models/api_model.dart b/flutter_course/lib/models/api_model.dart new file mode 100644 index 0000000..9d905ae --- /dev/null +++ b/flutter_course/lib/models/api_model.dart @@ -0,0 +1,21 @@ +class Failure implements Exception {} + +class ApiModel { + final T? result; + final E? failure; + + ApiModel({ + this.result, + this.failure, + }); + + bool get hasError => failure != null; + + factory ApiModel.success(T result) { + return ApiModel(result: result); + } + + factory ApiModel.error(E failure) { + return ApiModel(failure: failure); + } +} diff --git a/flutter_course/lib/models/comment_model.dart b/flutter_course/lib/models/comment_model.dart new file mode 100644 index 0000000..872094f --- /dev/null +++ b/flutter_course/lib/models/comment_model.dart @@ -0,0 +1,22 @@ +class CommentModel { + final int postId; + final int id; + final String name; + final String email; + final String body; + + CommentModel({ + required this.postId, + required this.id, + required this.name, + required this.email, + required this.body, + }); + + CommentModel.fromJson(Map json) + : postId = json['postId'], + id = json['id'], + name = json['name'], + email = json['email'], + body = json['body']; +} diff --git a/flutter_course/lib/models/movie_model.dart b/flutter_course/lib/models/movie_model.dart new file mode 100644 index 0000000..c38f56a --- /dev/null +++ b/flutter_course/lib/models/movie_model.dart @@ -0,0 +1,176 @@ +class MovieModel { + List? docs; + int? total; + int? limit; + int? page; + int? pages; + + MovieModel({this.docs, this.total, this.limit, this.page, this.pages}); + + MovieModel.fromJson(Map json) { + if (json['docs'] != null) { + docs = []; + json['docs'].forEach((v) { + docs!.add(Docs.fromJson(v)); + }); + } + total = json['total']; + limit = json['limit']; + page = json['page']; + pages = json['pages']; + } + + +} + +class Docs { + Logo? logo; + Poster? poster; + int? movieLength; + int? id; + String? type; + String? name; + String? description; + int? year; + String? alternativeName; + String? enName; + List? names; + String? shortDescription; + String? color; + bool isFavorite = false; + + Docs( + { this.logo, + this.poster, + this.movieLength, + this.id, + this.type, + this.name, + this.description, + this.year, + this.alternativeName, + this.enName, + this.names, + this.shortDescription, + this.color}); + + Docs.fromJson(Map json) { + logo = json['logo'] != null ? Logo.fromJson(json['logo']) : null; + poster = + json['poster'] != null ? Poster.fromJson(json['poster']) : null; + movieLength = json['movieLength']; + id = json['id']; + type = json['type']; + name = json['name']; + description = json['description']; + year = json['year']; + alternativeName = json['alternativeName']; + enName = json['enName']; + if (json['names'] != null) { + names = []; + json['names'].forEach((v) { + names!.add(Names.fromJson(v)); + }); + } + shortDescription = json['shortDescription']; + color = json['color']; + } + +} + +class Logo { + String? sId; + String? url; + + Logo({this.sId, this.url}); + + Logo.fromJson(Map json) { + sId = json['_id']; + url = json['url']; + } + +} + +class Poster { + String? sId; + String? url; + String? previewUrl; + + Poster({this.sId, this.url, this.previewUrl}); + + Poster.fromJson(Map json) { + sId = json['_id']; + url = json['url']; + previewUrl = json['previewUrl']; + } + + +} + +class Rating { + String? sId; + double? kp; + double? imdb; + double? filmCritics; + double? russianFilmCritics; + double? await; + + Rating( + {this.sId, + this.kp, + this.imdb, + this.filmCritics, + this.russianFilmCritics, + this.await}); + + Rating.fromJson(Map json) { + sId = json['_id']; + kp = json['kp']; + imdb = json['imdb']; + filmCritics = json['filmCritics']; + russianFilmCritics = json['russianFilmCritics']; + await = json['await']; + } + + +} + +class Votes { + String? sId; + int? kp; + int? imdb; + int? filmCritics; + int? russianFilmCritics; + int? await; + + Votes( + {this.sId, + this.kp, + this.imdb, + this.filmCritics, + this.russianFilmCritics, + this.await}); + + Votes.fromJson(Map json) { + sId = json['_id']; + kp = json['kp']; + imdb = json['imdb']; + filmCritics = json['filmCritics']; + russianFilmCritics = json['russianFilmCritics']; + await = json['await']; + } + +} + +class Names { + String? sId; + String? name; + + Names({this.sId, this.name}); + + Names.fromJson(Map json) { + sId = json['_id']; + name = json['name']; + } + +} \ No newline at end of file diff --git a/flutter_course/lib/models/post_model.dart b/flutter_course/lib/models/post_model.dart new file mode 100644 index 0000000..7eea525 --- /dev/null +++ b/flutter_course/lib/models/post_model.dart @@ -0,0 +1,19 @@ +class PostModel { + final int userId; + final int id; + final String title; + final String body; + + PostModel({ + required this.userId, + required this.id, + required this.title, + required this.body, + }); + + PostModel.fromJson(Map json) + : userId = json['userId'], + id = json['id'], + title = json['title'], + body = json['body']; +} diff --git a/flutter_course/lib/models/review_model.dart b/flutter_course/lib/models/review_model.dart new file mode 100644 index 0000000..43ad65a --- /dev/null +++ b/flutter_course/lib/models/review_model.dart @@ -0,0 +1,55 @@ +class ReviewModel { + List? docs; + int? total; + int? limit; + int? page; + int? pages; + + ReviewModel({this.docs, this.total, this.limit, this.page, this.pages}); + + ReviewModel.fromJson(Map json) { + if (json['docs'] != null) { + docs = []; + json['docs'].forEach((v) { + docs!.add(ReviewDocs.fromJson(v)); + }); + } + total = json['total']; + limit = json['limit']; + page = json['page']; + pages = json['pages']; + } + + +} + +class ReviewDocs { + int? id; + int? movieId; + String? title; + String? type; + String? review; + String? date; + String? author; + + ReviewDocs( + {this.id, + this.movieId, + this.title, + this.type, + this.review, + this.date, + this.author}); + + ReviewDocs.fromJson(Map json) { + id = json['id']; + movieId = json['movieId']; + title = json['title']; + type = json['type']; + review = json['review']; + date = json['date']; + author = json['author']; + } + + +} \ No newline at end of file diff --git a/flutter_course/lib/screens/favorite_screen.dart b/flutter_course/lib/screens/favorite_screen.dart new file mode 100644 index 0000000..a5a685a --- /dev/null +++ b/flutter_course/lib/screens/favorite_screen.dart @@ -0,0 +1,202 @@ +import 'package:flutter/material.dart'; +import 'package:get_it/get_it.dart'; +import '../bloc/movie_bloc.dart'; +import '../models/movie_model.dart'; + +import '../api_service.dart'; +import '../enums.dart'; +import '../theme/navigator_bar.dart'; +import '../theme/theme.dart'; +import 'review_screen.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + + + + +class FavoriteScreen extends StatefulWidget { + const FavoriteScreen({Key? key}) : super(key: key); + + @override + State createState() => _FavoriteScreenState(); + +} + + +class _FavoriteScreenState extends State { + + final ApiService service = ApiServiceDio.instance; + var state = ContentState.initial; + final movies = []; + + Future load() async { + setState(() { + state = ContentState.loading; + }); + final response = await service.getMovies(); + if (response.hasError) { + setState(() { + state = ContentState.failure; + movies.clear(); + }); + } else { + setState(() { + state = response.result!.isNotEmpty + ? ContentState.success + : ContentState.empty; + movies + ..clear() + ..addAll(response.result!); + }); + } + } + + @override + void initState() { + load(); + super.initState(); + } + + @override + Widget build(BuildContext context) { + final themeState = context.watch(); + return BlocBuilder( + bloc: GetIt.I.get(), + builder: (context, state) { + return Scaffold( + appBar: AppBar( + title: Text( + "Избранное", + style: Theme.of(context).appBarTheme.titleTextStyle, + ), + actions: [ + Switch( + value: themeState.isDark, + onChanged: (value) { + if (value) { + themeState.setDarkTheme(); + } else { + themeState.setLightTheme(); + } + }, + ), + ], + ), + drawer: NavBar(), + body: const _FavoriteView(), + ); + } + ); + } +} + +class _FavoriteView extends StatelessWidget { + + const _FavoriteView({ + Key? key + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return BlocBuilder( + bloc: GetIt.I.get(), + builder: (context, state) { + if (state is MovieInitialState || + state is MovieLoadingState) { + return const Center( + child: CircularProgressIndicator(), + ); + } + + if (state is MovieErrorState) { + return Text( state.message, + ); + } + + if (state is MovieLoadedState) { + final items = state.movies + ?.where((bk) => state.favoritesId.contains(bk.id)) + .toList(); + if (items?.isEmpty??false) { + return Center( + child: Text( + 'Список Избранные пуст', + style: Theme.of(context).textTheme.subtitle1, + ), + ); + } else { + return ListView.builder( + scrollDirection: Axis.vertical, + itemCount: items?.length, + itemBuilder: (context, i) => ListTile( + title: Row( children: [ + ClipRRect( + borderRadius: BorderRadius.circular(26), + child: Align( + alignment: Alignment.topCenter, + child: Image.network( + items?[i].poster?.previewUrl, + width: 70, + height: 250, + ), + ), + ), + const SizedBox(width: 20), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(items?[i].name??'Без названия', + style: Theme.of(context).textTheme.headline6, + ), + Text(items?[i].description??'Без описания', + style: Theme.of(context).textTheme.subtitle1, + maxLines: 7, + overflow: TextOverflow.ellipsis, + ), + ], + ), + ), + IconButton( + icon: Icon( + items?[i].isFavorite??false ? Icons.favorite : Icons.favorite_border, + size: 30, + color: Theme.of(context).iconTheme.color, + + ), + onPressed: () { + final bloc = GetIt.I.get(); + if (items?[i].id != null) { + if (items?[i].isFavorite??false) { + bloc.add(DeleteFromBookmarkEvent(items?[i].id as int)); + items?[i].isFavorite=false; + } else { + bloc.add(AddToBookmarkEvent(items?[i].id as int)); + items?[i].isFavorite=true; + } + } + }, + ), + + + + ], + ), + + + onTap: () { + navKey.currentState!.push( + MaterialPageRoute( + builder: (context) => ReviewScreen(movieId: items?[i].id??1), + ), + ); + }, + ), + ); + } + } + + return Container(); + }, + ); + } +} diff --git a/flutter_course/lib/screens/movie_screen.dart b/flutter_course/lib/screens/movie_screen.dart new file mode 100644 index 0000000..b2b2fa5 --- /dev/null +++ b/flutter_course/lib/screens/movie_screen.dart @@ -0,0 +1,202 @@ +import 'package:flutter/material.dart'; +import 'package:get_it/get_it.dart'; +import '../bloc/movie_bloc.dart'; +import '../models/movie_model.dart'; + +import '../api_service.dart'; +import '../enums.dart'; +import '../theme/navigator_bar.dart'; +import '../theme/theme.dart'; +import 'review_screen.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + + + + +class MovieScreen extends StatefulWidget { + const MovieScreen({Key? key}) : super(key: key); + + @override + State createState() => _MoviesScreenState(); + +} + + +class _MoviesScreenState extends State { + + + + final ApiService service = ApiServiceDio.instance; + var state = ContentState.initial; + final movies = []; + + Future load() async { + setState(() { + state = ContentState.loading; + }); + final response = await service.getMovies(); + if (response.hasError) { + setState(() { + state = ContentState.failure; + movies.clear(); + }); + } else { + setState(() { + state = response.result!.isNotEmpty + ? ContentState.success + : ContentState.empty; + movies + ..clear() + ..addAll(response.result!); + }); + } + } + + @override + void initState() { + load(); + super.initState(); + } + + @override + Widget build(BuildContext context) { + final themeState = context.watch(); + return BlocBuilder( + bloc: GetIt.I.get(), + builder: (context, state) { + return Scaffold( + + appBar: AppBar( + title: Text( + "Кинопремьеры", + style: Theme.of(context).appBarTheme.titleTextStyle, + ), + actions: [ + Switch( + value: themeState.isDark, + onChanged: (value) { + if (value) { + themeState.setDarkTheme(); + } else { + themeState.setLightTheme(); + } + }, + ), + ], + ), + drawer: NavBar(), + body: const _MoviesView(), + ); + } + ); + } +} + +class _MoviesView extends StatelessWidget { + + const _MoviesView({ + Key? key + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return BlocBuilder( + bloc: GetIt.I.get(), + builder: (context, state) { + if (state is MovieInitialState || + state is MovieLoadingState) { + return const Center( + child: CircularProgressIndicator(), + ); + } + + if (state is MovieErrorState) { + return Text( state.message, + ); + } + + if (state is MovieLoadedState) { + final items = state.movies; + if (items?.isEmpty??false) { + return const Center( + child: Text( + 'Список пуст', + style: TextStyle(fontSize: 20), + ), + ); + } else { + return ListView.builder( + scrollDirection: Axis.vertical, + itemCount: items?.length, + itemBuilder: (context, i) => ListTile( + title: Row( children: [ + ClipRRect( + borderRadius: BorderRadius.circular(26), + child: Align( + alignment: Alignment.topCenter, + child: Image.network( + items?[i].poster?.previewUrl, + width: 70, + height: 250, + ), + ), + ), + const SizedBox(width: 20), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(items?[i].name??'', + style: Theme.of(context).textTheme.headline6, + ), + Text(items?[i].description??'', + style: Theme.of(context).textTheme.subtitle1, + maxLines: 7, + overflow: TextOverflow.ellipsis, + ), + ], + ), + ), + IconButton( + icon: Icon( + items?[i].isFavorite??false ? Icons.favorite : Icons.favorite_border, + size: 30, + color: Theme.of(context).iconTheme.color, + ), + onPressed: () { + final bloc = GetIt.I.get(); + if (items?[i].id != null) { + if (items?[i].isFavorite??false) { + bloc.add(DeleteFromBookmarkEvent(items?[i].id as int)); + items?[i].isFavorite=false; + } else { + bloc.add(AddToBookmarkEvent(items?[i].id as int)); + items?[i].isFavorite=true; + } + } + }, + ), + + + + ], + ), + + + onTap: () { + navKey.currentState!.push( + MaterialPageRoute( + builder: (context) => ReviewScreen(movieId: items?[i].id??1), + ), + ); + }, + ), + ); + } + } + + return Container(); + }, + ); + } +} diff --git a/flutter_course/lib/screens/review_detail_screen.dart b/flutter_course/lib/screens/review_detail_screen.dart new file mode 100644 index 0000000..de7ad7f --- /dev/null +++ b/flutter_course/lib/screens/review_detail_screen.dart @@ -0,0 +1,125 @@ +import 'package:flutter/material.dart'; +import '../models/review_model.dart'; +import '../enums.dart'; + +class ReviewDetailScreen extends StatefulWidget { + final ReviewDocs review; + const ReviewDetailScreen({Key? key, required this.review}) : super(key: key); + + @override + State createState() => _ReviewDetailScreenState(); +} + +class _ReviewDetailScreenState extends State { + + + + var state = ReviewState.initial; + late ReviewDocs reviews; + Future load() async { + setState(() { + state = ReviewState.loading; + }); + reviews=widget.review; + // изменить + + setState(() { + state = ReviewState.success; + } + ); + } + + @override + void initState() { + load(); + super.initState(); + } + + @override + Widget build(BuildContext context) { + + return Scaffold( + appBar: AppBar( + title: const Text('Подробная информация по отзыву'), + ), + body: _ReviewDetailView( + state: state, + review: reviews, + ), + ); + } +} + +class _ReviewDetailView extends StatelessWidget { + final ReviewState state; + final ReviewDocs review; + + const _ReviewDetailView({ + Key? key, + required this.state, + required this.review, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + switch (state) { + case ReviewState.success: + return ListView.builder( + scrollDirection: Axis.vertical, + itemCount: 1, + itemBuilder: (context, i) => ListTile( + + title: Row( children: [ + + const SizedBox(width: 40,), + + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(review.author??'', + style: Theme.of(context).textTheme.headline6, + ), + Text(review.date??'', + style: Theme.of(context).textTheme.headline6, + ), + const SizedBox(height: 30,), + Text(review.title??'', + style: Theme.of(context).textTheme.headline6, + ), + Text(review.review??'', + style: Theme.of(context).textTheme.subtitle1, + ), + + ], + ), + ), + ], + ), + + ), + ); + case ReviewState.loading: + return const Center( + child: CircularProgressIndicator(), + ); + case ReviewState.empty: + return Center( + child: Text('Пустой список отзывов', + style: Theme.of(context).textTheme.subtitle1, + ), + ); + case ReviewState.failure: + return Center( + child: Text( + 'Ууупс, что-то пошло не так', + style: Theme.of(context).textTheme.subtitle1, + ), + ); + default: + return Center( + child: Text('Отзыв не загружен',style: Theme.of(context).textTheme.subtitle1,), + ); + } + } +} diff --git a/flutter_course/lib/screens/review_screen.dart b/flutter_course/lib/screens/review_screen.dart new file mode 100644 index 0000000..06b6cab --- /dev/null +++ b/flutter_course/lib/screens/review_screen.dart @@ -0,0 +1,151 @@ +import 'package:MovieReview/screens/review_detail_screen.dart'; +import 'package:flutter/material.dart'; +import '../models/review_model.dart'; +import '../api_service.dart'; +import '../enums.dart'; +import '../theme/theme.dart'; + +class ReviewScreen extends StatefulWidget { + final int movieId; + const ReviewScreen({Key? key, required this.movieId}) : super(key: key); + + @override + State createState() => _ReviewScreenState(); +} + +class _ReviewScreenState extends State { + + + final ApiService service = ApiServiceDio.instance; + var state = ReviewState.initial; + final reviews = []; + + + Future load() async { + setState(() { + state = ReviewState.loading; + }); + // изменить + final response = await service.getReviews(widget.movieId); + if (response.hasError) { + setState(() { + state = ReviewState.failure; + reviews.clear(); + }); + } else { + setState(() { + state = response.result!.isNotEmpty + ? ReviewState.success + : ReviewState.empty; + reviews + ..clear() + ..addAll(response.result!); + }); + } + } + + @override + void initState() { + load(); + super.initState(); + } + + @override + Widget build(BuildContext context) { + + return Scaffold( + appBar: AppBar( + title: const Text('Отзывы на фильм'), + ), + body: _ReviewView( + state: state, + reviews: reviews, + ), + ); + } +} + +class _ReviewView extends StatelessWidget { + final ReviewState state; + final List? reviews; + + const _ReviewView({ + Key? key, + required this.state, + this.reviews = const [], + }) : super(key: key); + + @override + Widget build(BuildContext context) { + switch (state) { + case ReviewState.success: + return ListView.builder( + scrollDirection: Axis.vertical, + itemCount: reviews?.length, + itemBuilder: (context, i) => ListTile( + + title: Row( children: [ + ((reviews?[i].type??"Нейтральный".compareTo("Позитивный"))==0 ) ? + const Icon(Icons.arrow_upward, color: Colors.green): + ((reviews?[i].type??"Нейтральный".compareTo("Негативный"))==0 ) ? + const Icon(Icons.arrow_downward, color: Colors.red): + const SizedBox(width: 40,), + + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(reviews?[i].author??'', + style: Theme.of(context).textTheme.headline6, + ), + Text(reviews?[i].date??'', + style: Theme.of(context).textTheme.headline6, + ), + const SizedBox(height: 30,), + Text(reviews?[i].title??'', + style: Theme.of(context).textTheme.headline6, + ), + Text(reviews?[i].review??'', + style: Theme.of(context).textTheme.subtitle1, + maxLines: 7, + overflow: TextOverflow.ellipsis, + ), + Divider(color: Theme.of(context).dividerTheme.color,), + ], + ), + ), + ], + ), + onTap: () { + navKey.currentState!.push( + MaterialPageRoute( + builder: (context) => ReviewDetailScreen(review: reviews![i]), + ), + ); + }, + ), + ); + case ReviewState.loading: + return const Center( + child: CircularProgressIndicator(), + ); + case ReviewState.empty: + return Center( + child: Text('Пустой список отзывов', + style: Theme.of(context).textTheme.subtitle1, + ), + ); + case ReviewState.failure: + return Center( + child: Text( + 'Ууупс, что-то пошло не так', + style: Theme.of(context).textTheme.subtitle1, + ), + ); + default: + return Center( + child: Text('Отзывы не загружены',style: Theme.of(context).textTheme.subtitle1,), + ); + } + } +} diff --git a/flutter_course/lib/theme/navigator_bar.dart b/flutter_course/lib/theme/navigator_bar.dart new file mode 100644 index 0000000..2d1feba --- /dev/null +++ b/flutter_course/lib/theme/navigator_bar.dart @@ -0,0 +1,38 @@ +import 'package:flutter/material.dart'; + +import '../screens/favorite_screen.dart'; +import '../screens/movie_screen.dart'; + +class NavBar extends StatelessWidget { + @override + Widget build(BuildContext context) { + return Drawer( + child: ListView( + // Remove padding + padding: EdgeInsets.zero, + children: [ + const UserAccountsDrawerHeader( + accountName: Text('kotelnikov-aa'), + accountEmail: Text('aleksey@kotelnikov.org'), + decoration: BoxDecoration( + color: Colors.blue, + ), + ), + ListTile( + leading: const Icon(Icons.person), + title: const Text('Кинопремьеры'), + onTap: () => Navigator.push(context, + MaterialPageRoute(builder: (context) => const MovieScreen())) + ), + ListTile( + leading: const Icon(Icons.favorite), + title: const Text("Закладки"), + onTap: () => Navigator.push(context, + MaterialPageRoute(builder: (context) => const FavoriteScreen())) + ), + + ], + ), + ); + } +} \ No newline at end of file diff --git a/flutter_course/lib/theme/theme.dart b/flutter_course/lib/theme/theme.dart new file mode 100644 index 0000000..0d05058 --- /dev/null +++ b/flutter_course/lib/theme/theme.dart @@ -0,0 +1,42 @@ +import 'package:flutter/material.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +final navKey = GlobalKey(); + +class ThemeState with ChangeNotifier { + final SharedPreferences storage; + + var _theme = ThemeMode.light; + + ThemeState(this.storage) { + _theme = _getTheme(); + } + + ThemeMode get theme => _theme; + + bool get isDark => _theme == ThemeMode.dark; + + ThemeMode _getTheme() { + final cache = storage.getString('theme') ?? ''; + + if (cache.isEmpty || cache == 'light') { + return ThemeMode.light; + } else { + return ThemeMode.dark; + } + } + + void setLightTheme() { + _change(ThemeMode.light); + } + + void setDarkTheme() { + _change(ThemeMode.dark); + } + + void _change(ThemeMode value) { + _theme = value; + storage.setString('theme', _theme.name); + notifyListeners(); + } +} diff --git a/flutter_course/pubspec.yaml b/flutter_course/pubspec.yaml new file mode 100644 index 0000000..1aa7899 --- /dev/null +++ b/flutter_course/pubspec.yaml @@ -0,0 +1,108 @@ +name: MovieReview +description: Course project of Epic school + +# The following line prevents the package from being accidentally published to +# pub.dev using `flutter pub publish`. This is preferred for private packages. +publish_to: 'none' # Remove this line if you wish to publish to pub.dev + +# The following defines the version and build number for your application. +# A version number is three numbers separated by dots, like 1.2.43 +# followed by an optional build number separated by a +. +# Both the version and the builder number may be overridden in flutter +# build by specifying --build-name and --build-number, respectively. +# In Android, build-name is used as versionName while build-number used as versionCode. +# Read more about Android versioning at https://developer.android.com/studio/publish/versioning +# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. +# Read more about iOS versioning at +# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html +version: 1.0.0+1 + +environment: + sdk: ">=2.17.1 <3.0.0" + +# Dependencies specify other packages that your package needs in order to work. +# To automatically upgrade your package dependencies to the latest versions +# consider running `flutter pub upgrade --major-versions`. Alternatively, +# dependencies can be manually updated by changing the version numbers below to +# the latest version available on pub.dev. To see which dependencies have newer +# versions available, run `flutter pub outdated`. +dependencies: + flutter: + sdk: flutter + intl: ^0.17.0 + http: ^0.13.4 + dio: ^4.0.0 + cached_network_image: ^3.2.0 + provider: ^6.0.2 + shared_preferences: ^2.0.13 + flutter_form_builder: ^7.1.1 + form_builder_extra_fields: ^7.1.0 + form_builder_validators: ^8.1.1 + form_builder_image_picker: ^2.0.0 + form_builder_file_picker: ^2.1.0 + flutter_localizations: + sdk: flutter + intl_utils: ^2.6.1 + bloc: ^8.0.3 + flutter_bloc: ^8.0.1 + mobx: ^2.0.7+2 + flutter_mobx: ^2.0.6+1 + validators2: ^3.0.0 + cupertino_icons: ^1.0.2 + favorite_button: ^0.0.4 + get_it: ^7.2.0 + +dev_dependencies: + flutter_test: + sdk: flutter + build_runner: ^2.1.11 + mobx_codegen: ^2.0.7 + + # The "flutter_lints" package below contains a set of recommended lints to + # encourage good coding practices. The lint set provided by the package is + # activated in the `analysis_options.yaml` file located at the root of your + # package. See that file for information about deactivating specific lint + # rules and activating additional ones. + flutter_lints: ^1.0.0 + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter packages. +flutter: + + # The following line ensures that the Material Icons font is + # included with your application, so that you can use the icons in + # the material Icons class. + uses-material-design: true + + # To add assets to your application, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/assets-and-images/#resolution-aware + + # For details regarding adding assets from package dependencies, see + # https://flutter.dev/assets-and-images/#from-packages + + # To add custom fonts to your application, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts from package dependencies, + # see https://flutter.dev/custom-fonts/#from-packages From 9a016796879f41741444e538c1660c6eb5768666 Mon Sep 17 00:00:00 2001 From: kotelnikov-aa <101976294+kotelnikov-aa@users.noreply.github.com> Date: Sun, 19 Jun 2022 08:33:22 +0700 Subject: [PATCH 2/2] course_project_hotfix1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Исправлены ошибки с кнопками навигации в светлой теме, исправлено закрашивание сердечек при выборе Избранного --- flutter_course/lib/main.dart | 12 ++++++++++-- flutter_course/lib/models/movie_model.dart | 2 +- .../lib/screens/favorite_screen.dart | 8 ++++++-- flutter_course/lib/screens/movie_screen.dart | 19 ++++++++++++------- .../lib/screens/review_detail_screen.dart | 1 + flutter_course/lib/screens/review_screen.dart | 1 + flutter_course/lib/theme/navigator_bar.dart | 3 ++- 7 files changed, 33 insertions(+), 13 deletions(-) diff --git a/flutter_course/lib/main.dart b/flutter_course/lib/main.dart index aa2b418..06ba34c 100644 --- a/flutter_course/lib/main.dart +++ b/flutter_course/lib/main.dart @@ -49,6 +49,7 @@ class App extends StatelessWidget { themeMode: state.theme, debugShowCheckedModeBanner: false, theme: ThemeData( + appBarTheme: AppBarTheme( backgroundColor: Colors.white, elevation: 0, @@ -60,7 +61,11 @@ class App extends StatelessWidget { iconTheme: const IconThemeData( color: Colors.red ), - dividerTheme: const DividerThemeData( + primaryIconTheme: const IconThemeData( + color: Colors.black + ), + + dividerTheme: const DividerThemeData( color: Colors.black ), textTheme: TextTheme( @@ -82,7 +87,10 @@ class App extends StatelessWidget { iconTheme: const IconThemeData( color: Colors.white ), - dividerTheme: const DividerThemeData( + primaryIconTheme: const IconThemeData( + color: Colors.white + ), + dividerTheme: const DividerThemeData( color: Colors.white ), textTheme: TextTheme( diff --git a/flutter_course/lib/models/movie_model.dart b/flutter_course/lib/models/movie_model.dart index c38f56a..88ea4cd 100644 --- a/flutter_course/lib/models/movie_model.dart +++ b/flutter_course/lib/models/movie_model.dart @@ -37,7 +37,7 @@ class Docs { List? names; String? shortDescription; String? color; - bool isFavorite = false; + bool? isFavorite; Docs( { this.logo, diff --git a/flutter_course/lib/screens/favorite_screen.dart b/flutter_course/lib/screens/favorite_screen.dart index a5a685a..1253f9d 100644 --- a/flutter_course/lib/screens/favorite_screen.dart +++ b/flutter_course/lib/screens/favorite_screen.dart @@ -63,7 +63,9 @@ class _FavoriteScreenState extends State { bloc: GetIt.I.get(), builder: (context, state) { return Scaffold( + appBar: AppBar( + iconTheme: Theme.of(context).primaryIconTheme, title: Text( "Избранное", style: Theme.of(context).appBarTheme.titleTextStyle, @@ -113,6 +115,8 @@ class _FavoriteView extends StatelessWidget { } if (state is MovieLoadedState) { + final favorites = state.favoritesId + .toList(); final items = state.movies ?.where((bk) => state.favoritesId.contains(bk.id)) .toList(); @@ -158,7 +162,7 @@ class _FavoriteView extends StatelessWidget { ), IconButton( icon: Icon( - items?[i].isFavorite??false ? Icons.favorite : Icons.favorite_border, + Icons.favorite , size: 30, color: Theme.of(context).iconTheme.color, @@ -166,7 +170,7 @@ class _FavoriteView extends StatelessWidget { onPressed: () { final bloc = GetIt.I.get(); if (items?[i].id != null) { - if (items?[i].isFavorite??false) { + if (favorites.contains(items?[i].id)) { bloc.add(DeleteFromBookmarkEvent(items?[i].id as int)); items?[i].isFavorite=false; } else { diff --git a/flutter_course/lib/screens/movie_screen.dart b/flutter_course/lib/screens/movie_screen.dart index b2b2fa5..86a92b9 100644 --- a/flutter_course/lib/screens/movie_screen.dart +++ b/flutter_course/lib/screens/movie_screen.dart @@ -65,8 +65,8 @@ class _MoviesScreenState extends State { bloc: GetIt.I.get(), builder: (context, state) { return Scaffold( - appBar: AppBar( + iconTheme: Theme.of(context).primaryIconTheme, title: Text( "Кинопремьеры", style: Theme.of(context).appBarTheme.titleTextStyle, @@ -84,8 +84,10 @@ class _MoviesScreenState extends State { ), ], ), - drawer: NavBar(), - body: const _MoviesView(), + drawer: NavBar(), + + + body: const _MoviesView(), ); } ); @@ -98,6 +100,8 @@ class _MoviesView extends StatelessWidget { Key? key }) : super(key: key); + + @override Widget build(BuildContext context) { return BlocBuilder( @@ -116,7 +120,10 @@ class _MoviesView extends StatelessWidget { } if (state is MovieLoadedState) { + final favorites = state.favoritesId + .toList(); final items = state.movies; + if (items?.isEmpty??false) { return const Center( child: Text( @@ -159,19 +166,17 @@ class _MoviesView extends StatelessWidget { ), IconButton( icon: Icon( - items?[i].isFavorite??false ? Icons.favorite : Icons.favorite_border, + favorites.contains(items?[i].id) ? Icons.favorite : Icons.favorite_border, size: 30, color: Theme.of(context).iconTheme.color, ), onPressed: () { final bloc = GetIt.I.get(); if (items?[i].id != null) { - if (items?[i].isFavorite??false) { + if (favorites.contains(items?[i].id) ) { bloc.add(DeleteFromBookmarkEvent(items?[i].id as int)); - items?[i].isFavorite=false; } else { bloc.add(AddToBookmarkEvent(items?[i].id as int)); - items?[i].isFavorite=true; } } }, diff --git a/flutter_course/lib/screens/review_detail_screen.dart b/flutter_course/lib/screens/review_detail_screen.dart index de7ad7f..ea4a862 100644 --- a/flutter_course/lib/screens/review_detail_screen.dart +++ b/flutter_course/lib/screens/review_detail_screen.dart @@ -40,6 +40,7 @@ class _ReviewDetailScreenState extends State { return Scaffold( appBar: AppBar( + iconTheme: Theme.of(context).primaryIconTheme, title: const Text('Подробная информация по отзыву'), ), body: _ReviewDetailView( diff --git a/flutter_course/lib/screens/review_screen.dart b/flutter_course/lib/screens/review_screen.dart index 06b6cab..687dc8a 100644 --- a/flutter_course/lib/screens/review_screen.dart +++ b/flutter_course/lib/screens/review_screen.dart @@ -55,6 +55,7 @@ class _ReviewScreenState extends State { return Scaffold( appBar: AppBar( + iconTheme: Theme.of(context).primaryIconTheme, title: const Text('Отзывы на фильм'), ), body: _ReviewView( diff --git a/flutter_course/lib/theme/navigator_bar.dart b/flutter_course/lib/theme/navigator_bar.dart index 2d1feba..8ac902b 100644 --- a/flutter_course/lib/theme/navigator_bar.dart +++ b/flutter_course/lib/theme/navigator_bar.dart @@ -7,6 +7,7 @@ class NavBar extends StatelessWidget { @override Widget build(BuildContext context) { return Drawer( + child: ListView( // Remove padding padding: EdgeInsets.zero, @@ -15,7 +16,7 @@ class NavBar extends StatelessWidget { accountName: Text('kotelnikov-aa'), accountEmail: Text('aleksey@kotelnikov.org'), decoration: BoxDecoration( - color: Colors.blue, + color: Colors.black, ), ), ListTile(