├── .env.example
├── .gitignore
├── .metadata
├── .vscode
└── launch.json
├── README.md
├── _external
└── wsserver
│ ├── .gitignore
│ ├── index.html
│ ├── index.js
│ ├── package.json
│ └── yarn.lock
├── _files
├── logo.png
├── logo.psd
├── screenshot-1.jpg
├── screenshot-1.psd
├── screenshot-2.jpg
├── screenshot-3.jpg
├── screenshot-3.psd
├── screenshot.jpg
└── splash.psd
├── analysis_options.yaml
├── android
├── .gitignore
├── app
│ ├── build.gradle
│ └── src
│ │ ├── debug
│ │ └── AndroidManifest.xml
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── kotlin
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── learning_flutter_riverpod
│ │ │ │ └── MainActivity.kt
│ │ └── res
│ │ │ ├── drawable-v21
│ │ │ ├── background.png
│ │ │ └── launch_background.xml
│ │ │ ├── drawable
│ │ │ ├── background.png
│ │ │ └── launch_background.xml
│ │ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── values-night
│ │ │ └── styles.xml
│ │ │ ├── values-v31
│ │ │ └── styles.xml
│ │ │ └── values
│ │ │ └── styles.xml
│ │ └── profile
│ │ └── AndroidManifest.xml
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ └── gradle-wrapper.properties
└── settings.gradle
├── assets
├── images
│ ├── logo.png
│ └── splash.png
└── lottie
│ └── .gitignore
├── ios
├── .gitignore
├── Flutter
│ ├── AppFrameworkInfo.plist
│ ├── Debug.xcconfig
│ └── Release.xcconfig
├── Runner.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ ├── IDEWorkspaceChecks.plist
│ │ │ └── WorkspaceSettings.xcsettings
│ └── xcshareddata
│ │ └── xcschemes
│ │ └── Runner.xcscheme
├── Runner.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ │ ├── IDEWorkspaceChecks.plist
│ │ └── WorkspaceSettings.xcsettings
└── Runner
│ ├── AppDelegate.swift
│ ├── Assets.xcassets
│ ├── AppIcon.appiconset
│ │ ├── Contents.json
│ │ ├── Icon-App-1024x1024@1x.png
│ │ ├── Icon-App-20x20@1x.png
│ │ ├── Icon-App-20x20@2x.png
│ │ ├── Icon-App-20x20@3x.png
│ │ ├── Icon-App-29x29@1x.png
│ │ ├── Icon-App-29x29@2x.png
│ │ ├── Icon-App-29x29@3x.png
│ │ ├── Icon-App-40x40@1x.png
│ │ ├── Icon-App-40x40@2x.png
│ │ ├── Icon-App-40x40@3x.png
│ │ ├── Icon-App-50x50@1x.png
│ │ ├── Icon-App-50x50@2x.png
│ │ ├── Icon-App-57x57@1x.png
│ │ ├── Icon-App-57x57@2x.png
│ │ ├── Icon-App-60x60@2x.png
│ │ ├── Icon-App-60x60@3x.png
│ │ ├── Icon-App-72x72@1x.png
│ │ ├── Icon-App-72x72@2x.png
│ │ ├── Icon-App-76x76@1x.png
│ │ ├── Icon-App-76x76@2x.png
│ │ └── Icon-App-83.5x83.5@2x.png
│ ├── LaunchBackground.imageset
│ │ ├── Contents.json
│ │ └── background.png
│ └── LaunchImage.imageset
│ │ ├── Contents.json
│ │ ├── LaunchImage.png
│ │ ├── LaunchImage@2x.png
│ │ ├── LaunchImage@3x.png
│ │ └── README.md
│ ├── Base.lproj
│ ├── LaunchScreen.storyboard
│ └── Main.storyboard
│ ├── Info.plist
│ └── Runner-Bridging-Header.h
├── lib
├── main.dart
└── src
│ ├── app_routes.dart
│ ├── common_widgets
│ ├── connectivity_warning.dart
│ └── error_screen.dart
│ ├── features
│ ├── auth
│ │ ├── data
│ │ │ ├── enums
│ │ │ │ └── auth_status.dart
│ │ │ ├── exceptions
│ │ │ │ └── login_exception.dart
│ │ │ ├── models
│ │ │ │ ├── auth_state.dart
│ │ │ │ ├── login.dart
│ │ │ │ └── user.dart
│ │ │ ├── providers
│ │ │ │ └── auth_provider.dart
│ │ │ └── repositories
│ │ │ │ └── auth_repository.dart
│ │ └── ui
│ │ │ ├── auth_screen.dart
│ │ │ ├── dashboard_screen.dart
│ │ │ └── login_form.dart
│ ├── calculator
│ │ ├── data
│ │ │ ├── models
│ │ │ │ └── calculator.dart
│ │ │ └── providers
│ │ │ │ └── calculator_provider.dart
│ │ └── ui
│ │ │ └── calculator_screen.dart
│ ├── counter
│ │ ├── providers
│ │ │ ├── counter_provider.dart
│ │ │ └── timer_provider.dart
│ │ └── ui
│ │ │ ├── counter_screen.dart
│ │ │ └── timer_screen.dart
│ ├── home
│ │ ├── data
│ │ │ ├── models
│ │ │ │ └── entry.dart
│ │ │ └── providers
│ │ │ │ └── home_provider.dart
│ │ └── ui
│ │ │ └── home_screen.dart
│ ├── movies
│ │ ├── data
│ │ │ ├── environment_config.dart
│ │ │ ├── exceptions
│ │ │ │ └── movies_exception.dart
│ │ │ ├── models
│ │ │ │ ├── movie.dart
│ │ │ │ └── movie_pagination.dart
│ │ │ ├── providers
│ │ │ │ └── movies_provider.dart
│ │ │ └── repositories
│ │ │ │ └── movie_repository.dart
│ │ └── ui
│ │ │ ├── error_body.dart
│ │ │ ├── movie_box.dart
│ │ │ ├── movies_paginated_screen.dart
│ │ │ └── movies_screen.dart
│ ├── network_status
│ │ ├── providers
│ │ │ └── network_status_provider.dart
│ │ └── ui
│ │ │ └── network_status_screen.dart
│ ├── products
│ │ ├── data
│ │ │ ├── exceptions
│ │ │ │ └── products_exception.dart
│ │ │ ├── models
│ │ │ │ ├── product.dart
│ │ │ │ └── product_pagination.dart
│ │ │ ├── providers
│ │ │ │ ├── cart_provider.dart
│ │ │ │ └── product_provider.dart
│ │ │ ├── repositories
│ │ │ │ └── product_repository.dart
│ │ │ └── utils
│ │ │ │ └── api_client.dart
│ │ └── ui
│ │ │ ├── error_body.dart
│ │ │ ├── loading.dart
│ │ │ ├── product_item.dart
│ │ │ ├── products_screen.dart
│ │ │ └── view_product_screen.dart
│ ├── providers
│ │ ├── providers
│ │ │ └── providers_provider.dart
│ │ └── ui
│ │ │ └── providers_screen.dart
│ ├── settings
│ │ ├── data
│ │ │ ├── models
│ │ │ │ ├── theme_scheme.dart
│ │ │ │ └── theme_state.dart
│ │ │ └── providers
│ │ │ │ └── theme_provider.dart
│ │ └── ui
│ │ │ └── settings_screen.dart
│ ├── stopwatch
│ │ ├── data
│ │ │ ├── models
│ │ │ │ └── timer.dart
│ │ │ └── providers
│ │ │ │ └── stopwatch_provider.dart
│ │ └── ui
│ │ │ └── stopwatch_screen.dart
│ ├── trivia
│ │ ├── data
│ │ │ ├── enums
│ │ │ │ ├── difficulty.dart
│ │ │ │ └── quiz_status.dart
│ │ │ ├── models
│ │ │ │ ├── failure.dart
│ │ │ │ ├── question.dart
│ │ │ │ └── quiz_state.dart
│ │ │ ├── providers
│ │ │ │ └── trivia_provider.dart
│ │ │ └── repositories
│ │ │ │ ├── base_repository.dart
│ │ │ │ └── quiz_repository.dart
│ │ └── ui
│ │ │ ├── answer_card.dart
│ │ │ ├── box_shadow.dart
│ │ │ ├── confetti_card.dart
│ │ │ ├── custom_button.dart
│ │ │ ├── quiz_error.dart
│ │ │ ├── quiz_questions.dart
│ │ │ ├── quiz_results.dart
│ │ │ └── trivia_screen.dart
│ └── websockets
│ │ ├── providers
│ │ └── websockets_provider.dart
│ │ └── ui
│ │ └── websockets_screen.dart
│ └── utils
│ ├── async_snackbar.dart
│ ├── contants.dart
│ ├── context_snackbar.dart
│ └── list_scroll_mixin.dart
├── linux
├── .gitignore
├── CMakeLists.txt
├── flutter
│ ├── CMakeLists.txt
│ ├── generated_plugin_registrant.cc
│ ├── generated_plugin_registrant.h
│ └── generated_plugins.cmake
├── main.cc
├── my_application.cc
└── my_application.h
├── macos
├── .gitignore
├── Flutter
│ ├── Flutter-Debug.xcconfig
│ ├── Flutter-Release.xcconfig
│ └── GeneratedPluginRegistrant.swift
├── Runner.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ └── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ └── xcshareddata
│ │ └── xcschemes
│ │ └── Runner.xcscheme
├── Runner.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ │ └── IDEWorkspaceChecks.plist
└── Runner
│ ├── AppDelegate.swift
│ ├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ ├── Contents.json
│ │ ├── app_icon_1024.png
│ │ ├── app_icon_128.png
│ │ ├── app_icon_16.png
│ │ ├── app_icon_256.png
│ │ ├── app_icon_32.png
│ │ ├── app_icon_512.png
│ │ └── app_icon_64.png
│ ├── Base.lproj
│ └── MainMenu.xib
│ ├── Configs
│ ├── AppInfo.xcconfig
│ ├── Debug.xcconfig
│ ├── Release.xcconfig
│ └── Warnings.xcconfig
│ ├── DebugProfile.entitlements
│ ├── Info.plist
│ ├── MainFlutterWindow.swift
│ └── Release.entitlements
├── pubspec.lock
├── pubspec.yaml
├── test
└── widget_test.dart
├── web
├── favicon.png
├── icons
│ ├── Icon-192.png
│ ├── Icon-512.png
│ ├── Icon-maskable-192.png
│ └── Icon-maskable-512.png
├── index.html
├── manifest.json
└── splash
│ ├── img
│ └── light-background.png
│ ├── splash.js
│ └── style.css
└── windows
├── .gitignore
├── CMakeLists.txt
├── flutter
├── CMakeLists.txt
├── generated_plugin_registrant.cc
├── generated_plugin_registrant.h
└── generated_plugins.cmake
└── runner
├── CMakeLists.txt
├── Runner.rc
├── flutter_window.cpp
├── flutter_window.h
├── main.cpp
├── resource.h
├── resources
└── app_icon.ico
├── runner.exe.manifest
├── utils.cpp
├── utils.h
├── win32_window.cpp
└── win32_window.h
/.env.example:
--------------------------------------------------------------------------------
1 | MOVIEDB_KEY=
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Miscellaneous
2 | *.class
3 | *.log
4 | *.pyc
5 | *.swp
6 | .DS_Store
7 | .atom/
8 | .buildlog/
9 | .history
10 | .svn/
11 | migrate_working_dir/
12 |
13 | # IntelliJ related
14 | *.iml
15 | *.ipr
16 | *.iws
17 | .idea/
18 |
19 | # The .vscode folder contains launch configuration and tasks you configure in
20 | # VS Code which you may wish to be included in version control, so this line
21 | # is commented out by default.
22 | #.vscode/
23 |
24 | # Flutter/Dart/Pub related
25 | **/doc/api/
26 | **/ios/Flutter/.last_build_id
27 | .dart_tool/
28 | .flutter-plugins
29 | .flutter-plugins-dependencies
30 | .packages
31 | .pub-cache/
32 | .pub/
33 | /build/
34 |
35 | # Symbolication related
36 | app.*.symbols
37 |
38 | # Obfuscation related
39 | app.*.map.json
40 |
41 | # Android Studio will place build artifacts here
42 | /android/app/debug
43 | /android/app/profile
44 | /android/app/release
45 |
46 | # environment files
47 | .env
48 |
--------------------------------------------------------------------------------
/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled.
5 |
6 | version:
7 | revision: e3c29ec00c9c825c891d75054c63fcc46454dca1
8 | channel: stable
9 |
10 | project_type: app
11 |
12 | # Tracks metadata for the flutter migrate command
13 | migration:
14 | platforms:
15 | - platform: root
16 | create_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1
17 | base_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1
18 | - platform: android
19 | create_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1
20 | base_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1
21 | - platform: ios
22 | create_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1
23 | base_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1
24 | - platform: linux
25 | create_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1
26 | base_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1
27 | - platform: macos
28 | create_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1
29 | base_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1
30 | - platform: web
31 | create_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1
32 | base_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1
33 | - platform: windows
34 | create_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1
35 | base_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1
36 |
37 | # User provided section
38 |
39 | # List of Local paths (relative to this file) that should be
40 | # ignored by the migrate tool.
41 | #
42 | # Files that are not part of the templates will be ignored by default.
43 | unmanaged_files:
44 | - 'lib/main.dart'
45 | - 'ios/Runner.xcodeproj/project.pbxproj'
46 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": "riverpod_counter",
9 | "request": "launch",
10 | "type": "dart",
11 | "deviceId": "chrome"
12 | },
13 | {
14 | "name": "riverpod_counter (device)",
15 | "request": "launch",
16 | "type": "dart",
17 | },
18 | {
19 | "name": "riverpod_counter (profile mode)",
20 | "request": "launch",
21 | "type": "dart",
22 | "flutterMode": "profile"
23 | },
24 | {
25 | "name": "riverpod_counter (release mode)",
26 | "request": "launch",
27 | "type": "dart",
28 | "flutterMode": "release"
29 | }
30 | ]
31 | }
--------------------------------------------------------------------------------
/_external/wsserver/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
--------------------------------------------------------------------------------
/_external/wsserver/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Socket.IO chat
5 |
57 |
58 |
59 |
60 |
63 |
64 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/_external/wsserver/index.js:
--------------------------------------------------------------------------------
1 | const WebSocket = require("ws");
2 |
3 | // start the server and specify the port number
4 | const port = 8080;
5 | const wss = new WebSocket.Server({ port: port });
6 | console.log(`[WebSocket] Starting WebSocket server on localhost:${port}`);
7 |
8 | wss.on("connection", (ws, request) => {
9 | const clientIp = ws._socket.remoteAddress;
10 |
11 | console.log(`[WebSocket] Client with IP ${clientIp} has connected`);
12 | ws.send("Thanks for connecting to this nodejs websocket server");
13 |
14 | ws.on("message", (message) => {
15 | if (message.toString() != "send_something") return;
16 |
17 | wss.clients.forEach((client) => {
18 | if (client.readyState === WebSocket.OPEN) {
19 | setInterval(() => {
20 | const strangeMessage = Date.now().toString();
21 |
22 | client.send(strangeMessage);
23 | }, 4000);
24 | }
25 | });
26 |
27 | console.log(`[WebSocket] Message ${message} was received`);
28 | });
29 | });
30 |
--------------------------------------------------------------------------------
/_external/wsserver/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "server",
3 | "version": "1.0.0",
4 | "main": "index.js",
5 | "license": "MIT",
6 | "scripts": {
7 | "start": "nodemon"
8 | },
9 | "dependencies": {
10 | "ws": "^8.9.0"
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/_external/wsserver/yarn.lock:
--------------------------------------------------------------------------------
1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2 | # yarn lockfile v1
3 |
4 |
5 | ws@^8.9.0:
6 | version "8.9.0"
7 | resolved "https://registry.yarnpkg.com/ws/-/ws-8.9.0.tgz#2a994bb67144be1b53fe2d23c53c028adeb7f45e"
8 | integrity sha512-Ja7nszREasGaYUYCI2k4lCKIRTt+y7XuqVoHR44YpI49TtryyqbqvDMn5eqfW7e6HzTukDRIsXqzVHScqRcafg==
9 |
--------------------------------------------------------------------------------
/_files/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/_files/logo.png
--------------------------------------------------------------------------------
/_files/logo.psd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/_files/logo.psd
--------------------------------------------------------------------------------
/_files/screenshot-1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/_files/screenshot-1.jpg
--------------------------------------------------------------------------------
/_files/screenshot-1.psd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/_files/screenshot-1.psd
--------------------------------------------------------------------------------
/_files/screenshot-2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/_files/screenshot-2.jpg
--------------------------------------------------------------------------------
/_files/screenshot-3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/_files/screenshot-3.jpg
--------------------------------------------------------------------------------
/_files/screenshot-3.psd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/_files/screenshot-3.psd
--------------------------------------------------------------------------------
/_files/screenshot.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/_files/screenshot.jpg
--------------------------------------------------------------------------------
/_files/splash.psd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/_files/splash.psd
--------------------------------------------------------------------------------
/analysis_options.yaml:
--------------------------------------------------------------------------------
1 | include: package:flutter_lints/flutter.yaml
2 |
3 | analyzer:
4 | strong-mode:
5 | implicit-casts: false
6 | # implicit-dynamic: false
7 |
8 | exclude:
9 | - "**/*.g.dart"
10 | # - "**/*.freezed.dart"
11 | errors:
12 | invalid_annotation_target: ignore
13 |
14 | linter:
15 | rules:
16 | avoid_types_on_closure_parameters: true
17 | avoid_void_async: true
18 | cancel_subscriptions: true
19 | close_sinks: true
20 | directives_ordering: true
21 | package_api_docs: true
22 | package_prefixed_library_names: true
23 | prefer_relative_imports: true
24 | prefer_single_quotes: true
25 | test_types_in_equals: true
26 | throw_in_finally: true
27 | unawaited_futures: true
28 | unnecessary_statements: true
29 | use_super_parameters: false
30 | prefer_const_literals_to_create_immutables: true
31 |
--------------------------------------------------------------------------------
/android/.gitignore:
--------------------------------------------------------------------------------
1 | gradle-wrapper.jar
2 | /.gradle
3 | /captures/
4 | /gradlew
5 | /gradlew.bat
6 | /local.properties
7 | GeneratedPluginRegistrant.java
8 |
9 | # Remember to never publicly share your keystore.
10 | # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11 | key.properties
12 | **/*.keystore
13 | **/*.jks
14 |
--------------------------------------------------------------------------------
/android/app/build.gradle:
--------------------------------------------------------------------------------
1 | def localProperties = new Properties()
2 | def localPropertiesFile = rootProject.file('local.properties')
3 | if (localPropertiesFile.exists()) {
4 | localPropertiesFile.withReader('UTF-8') { reader ->
5 | localProperties.load(reader)
6 | }
7 | }
8 |
9 | def flutterRoot = localProperties.getProperty('flutter.sdk')
10 | if (flutterRoot == null) {
11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12 | }
13 |
14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
15 | if (flutterVersionCode == null) {
16 | flutterVersionCode = '1'
17 | }
18 |
19 | def flutterVersionName = localProperties.getProperty('flutter.versionName')
20 | if (flutterVersionName == null) {
21 | flutterVersionName = '1.0'
22 | }
23 |
24 |
25 | def flutterMinSdkVersion = localProperties.getProperty('flutter.minSdkVersion')
26 | if (flutterMinSdkVersion == null) {
27 | flutterMinSdkVersion = 29
28 | }
29 |
30 | def flutterTargetSdkVersion = localProperties.getProperty('flutter.targetSdkVersion')
31 | if (flutterTargetSdkVersion == null) {
32 | flutterTargetSdkVersion = 31
33 | }
34 |
35 | def flutterCompileSdkVersion = localProperties.getProperty('flutter.compileSdkVersion')
36 | if (flutterCompileSdkVersion == null) {
37 | flutterCompileSdkVersion = flutter.compileSdkVersion
38 | }
39 |
40 | apply plugin: 'com.android.application'
41 | apply plugin: 'kotlin-android'
42 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
43 |
44 | android {
45 | compileSdkVersion flutterCompileSdkVersion.toInteger()
46 | ndkVersion flutter.ndkVersion
47 |
48 | compileOptions {
49 | sourceCompatibility JavaVersion.VERSION_1_8
50 | targetCompatibility JavaVersion.VERSION_1_8
51 | }
52 |
53 | kotlinOptions {
54 | jvmTarget = '1.8'
55 | }
56 |
57 | sourceSets {
58 | main.java.srcDirs += 'src/main/kotlin'
59 | }
60 |
61 | defaultConfig {
62 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
63 | applicationId "com.example.learning_flutter_riverpod"
64 | // You can update the following values to match your application needs.
65 | // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
66 | minSdkVersion flutterMinSdkVersion.toInteger()
67 | targetSdkVersion flutterTargetSdkVersion.toInteger()
68 | versionCode flutterVersionCode.toInteger()
69 | versionName flutterVersionName
70 | }
71 |
72 | buildTypes {
73 | release {
74 | // TODO: Add your own signing config for the release build.
75 | // Signing with the debug keys for now, so `flutter run --release` works.
76 | signingConfig signingConfigs.debug
77 | }
78 | }
79 | }
80 |
81 | flutter {
82 | source '../..'
83 | }
84 |
85 | dependencies {
86 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
87 | }
88 |
--------------------------------------------------------------------------------
/android/app/src/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
10 |
11 |
19 |
23 |
27 |
28 |
29 |
30 |
31 |
32 |
34 |
37 |
38 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/android/app/src/main/kotlin/com/example/learning_flutter_riverpod/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.example.learning_flutter_riverpod
2 |
3 | import io.flutter.embedding.android.FlutterActivity
4 |
5 | class MainActivity: FlutterActivity() {
6 | }
7 |
--------------------------------------------------------------------------------
/android/app/src/main/res/drawable-v21/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/android/app/src/main/res/drawable-v21/background.png
--------------------------------------------------------------------------------
/android/app/src/main/res/drawable-v21/launch_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/android/app/src/main/res/drawable/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/android/app/src/main/res/drawable/background.png
--------------------------------------------------------------------------------
/android/app/src/main/res/drawable/launch_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/values-night/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/android/app/src/main/res/values-v31/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/android/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
18 |
21 |
22 |
--------------------------------------------------------------------------------
/android/app/src/profile/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.kotlin_version = '1.6.10'
3 | repositories {
4 | google()
5 | mavenCentral()
6 | }
7 |
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:7.1.2'
10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11 | }
12 | }
13 |
14 | allprojects {
15 | repositories {
16 | google()
17 | mavenCentral()
18 | }
19 | }
20 |
21 | rootProject.buildDir = '../build'
22 | subprojects {
23 | project.buildDir = "${rootProject.buildDir}/${project.name}"
24 | }
25 | subprojects {
26 | project.evaluationDependsOn(':app')
27 | }
28 |
29 | task clean(type: Delete) {
30 | delete rootProject.buildDir
31 | }
32 |
--------------------------------------------------------------------------------
/android/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Xmx1536M
2 | android.useAndroidX=true
3 | android.enableJetifier=true
4 |
--------------------------------------------------------------------------------
/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | zipStoreBase=GRADLE_USER_HOME
4 | zipStorePath=wrapper/dists
5 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
6 |
--------------------------------------------------------------------------------
/android/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
3 | def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
4 | def properties = new Properties()
5 |
6 | assert localPropertiesFile.exists()
7 | localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
8 |
9 | def flutterSdkPath = properties.getProperty("flutter.sdk")
10 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
11 | apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
12 |
--------------------------------------------------------------------------------
/assets/images/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/assets/images/logo.png
--------------------------------------------------------------------------------
/assets/images/splash.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/assets/images/splash.png
--------------------------------------------------------------------------------
/assets/lottie/.gitignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/assets/lottie/.gitignore
--------------------------------------------------------------------------------
/ios/.gitignore:
--------------------------------------------------------------------------------
1 | **/dgph
2 | *.mode1v3
3 | *.mode2v3
4 | *.moved-aside
5 | *.pbxuser
6 | *.perspectivev3
7 | **/*sync/
8 | .sconsign.dblite
9 | .tags*
10 | **/.vagrant/
11 | **/DerivedData/
12 | Icon?
13 | **/Pods/
14 | **/.symlinks/
15 | profile
16 | xcuserdata
17 | **/.generated/
18 | Flutter/App.framework
19 | Flutter/Flutter.framework
20 | Flutter/Flutter.podspec
21 | Flutter/Generated.xcconfig
22 | Flutter/ephemeral/
23 | Flutter/app.flx
24 | Flutter/app.zip
25 | Flutter/flutter_assets/
26 | Flutter/flutter_export_environment.sh
27 | ServiceDefinitions.json
28 | Runner/GeneratedPluginRegistrant.*
29 |
30 | # Exceptions to above rules.
31 | !default.mode1v3
32 | !default.mode2v3
33 | !default.pbxuser
34 | !default.perspectivev3
35 |
--------------------------------------------------------------------------------
/ios/Flutter/AppFrameworkInfo.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | App
9 | CFBundleIdentifier
10 | io.flutter.flutter.app
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | App
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1.0
23 | MinimumOSVersion
24 | 11.0
25 |
26 |
27 |
--------------------------------------------------------------------------------
/ios/Flutter/Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include "Generated.xcconfig"
2 |
--------------------------------------------------------------------------------
/ios/Flutter/Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include "Generated.xcconfig"
2 |
--------------------------------------------------------------------------------
/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PreviewsEnabled
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
37 |
38 |
39 |
40 |
41 |
42 |
52 |
54 |
60 |
61 |
62 |
63 |
69 |
71 |
77 |
78 |
79 |
80 |
82 |
83 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/ios/Runner.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PreviewsEnabled
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/ios/Runner/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | import UIKit
2 | import Flutter
3 |
4 | @UIApplicationMain
5 | @objc class AppDelegate: FlutterAppDelegate {
6 | override func application(
7 | _ application: UIApplication,
8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
9 | ) -> Bool {
10 | GeneratedPluginRegistrant.register(with: self)
11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions)
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "size" : "20x20",
5 | "idiom" : "iphone",
6 | "filename" : "Icon-App-20x20@2x.png",
7 | "scale" : "2x"
8 | },
9 | {
10 | "size" : "20x20",
11 | "idiom" : "iphone",
12 | "filename" : "Icon-App-20x20@3x.png",
13 | "scale" : "3x"
14 | },
15 | {
16 | "size" : "29x29",
17 | "idiom" : "iphone",
18 | "filename" : "Icon-App-29x29@1x.png",
19 | "scale" : "1x"
20 | },
21 | {
22 | "size" : "29x29",
23 | "idiom" : "iphone",
24 | "filename" : "Icon-App-29x29@2x.png",
25 | "scale" : "2x"
26 | },
27 | {
28 | "size" : "29x29",
29 | "idiom" : "iphone",
30 | "filename" : "Icon-App-29x29@3x.png",
31 | "scale" : "3x"
32 | },
33 | {
34 | "size" : "40x40",
35 | "idiom" : "iphone",
36 | "filename" : "Icon-App-40x40@2x.png",
37 | "scale" : "2x"
38 | },
39 | {
40 | "size" : "40x40",
41 | "idiom" : "iphone",
42 | "filename" : "Icon-App-40x40@3x.png",
43 | "scale" : "3x"
44 | },
45 | {
46 | "size" : "60x60",
47 | "idiom" : "iphone",
48 | "filename" : "Icon-App-60x60@2x.png",
49 | "scale" : "2x"
50 | },
51 | {
52 | "size" : "60x60",
53 | "idiom" : "iphone",
54 | "filename" : "Icon-App-60x60@3x.png",
55 | "scale" : "3x"
56 | },
57 | {
58 | "size" : "20x20",
59 | "idiom" : "ipad",
60 | "filename" : "Icon-App-20x20@1x.png",
61 | "scale" : "1x"
62 | },
63 | {
64 | "size" : "20x20",
65 | "idiom" : "ipad",
66 | "filename" : "Icon-App-20x20@2x.png",
67 | "scale" : "2x"
68 | },
69 | {
70 | "size" : "29x29",
71 | "idiom" : "ipad",
72 | "filename" : "Icon-App-29x29@1x.png",
73 | "scale" : "1x"
74 | },
75 | {
76 | "size" : "29x29",
77 | "idiom" : "ipad",
78 | "filename" : "Icon-App-29x29@2x.png",
79 | "scale" : "2x"
80 | },
81 | {
82 | "size" : "40x40",
83 | "idiom" : "ipad",
84 | "filename" : "Icon-App-40x40@1x.png",
85 | "scale" : "1x"
86 | },
87 | {
88 | "size" : "40x40",
89 | "idiom" : "ipad",
90 | "filename" : "Icon-App-40x40@2x.png",
91 | "scale" : "2x"
92 | },
93 | {
94 | "size" : "76x76",
95 | "idiom" : "ipad",
96 | "filename" : "Icon-App-76x76@1x.png",
97 | "scale" : "1x"
98 | },
99 | {
100 | "size" : "76x76",
101 | "idiom" : "ipad",
102 | "filename" : "Icon-App-76x76@2x.png",
103 | "scale" : "2x"
104 | },
105 | {
106 | "size" : "83.5x83.5",
107 | "idiom" : "ipad",
108 | "filename" : "Icon-App-83.5x83.5@2x.png",
109 | "scale" : "2x"
110 | },
111 | {
112 | "size" : "1024x1024",
113 | "idiom" : "ios-marketing",
114 | "filename" : "Icon-App-1024x1024@1x.png",
115 | "scale" : "1x"
116 | }
117 | ],
118 | "info" : {
119 | "version" : 1,
120 | "author" : "xcode"
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-50x50@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-50x50@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-50x50@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-50x50@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/LaunchBackground.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "filename" : "background.png",
5 | "idiom" : "universal",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "author" : "xcode",
19 | "version" : 1
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/LaunchBackground.imageset/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/LaunchBackground.imageset/background.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "filename" : "LaunchImage.png",
5 | "idiom" : "universal",
6 | "scale" : "1x"
7 | },
8 | {
9 | "filename" : "LaunchImage@2x.png",
10 | "idiom" : "universal",
11 | "scale" : "2x"
12 | },
13 | {
14 | "filename" : "LaunchImage@3x.png",
15 | "idiom" : "universal",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "author" : "xcode",
21 | "version" : 1
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syntaxlexx/learning-flutter-riverpod/45180906735bcf0027abd0b15e2998fe114b5c3f/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md:
--------------------------------------------------------------------------------
1 | # Launch Screen Assets
2 |
3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory.
4 |
5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images.
--------------------------------------------------------------------------------
/ios/Runner/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/ios/Runner/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/ios/Runner/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleDisplayName
8 | Learning Flutter Riverpod
9 | CFBundleExecutable
10 | $(EXECUTABLE_NAME)
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | learning_flutter_riverpod
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | $(FLUTTER_BUILD_NAME)
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | $(FLUTTER_BUILD_NUMBER)
25 | LSRequiresIPhoneOS
26 |
27 | UILaunchStoryboardName
28 | LaunchScreen
29 | UIMainStoryboardFile
30 | Main
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 | UISupportedInterfaceOrientations~ipad
38 |
39 | UIInterfaceOrientationPortrait
40 | UIInterfaceOrientationPortraitUpsideDown
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 | UIViewControllerBasedStatusBarAppearance
45 |
46 | CADisableMinimumFrameDurationOnPhone
47 |
48 | UIApplicationSupportsIndirectInputEvents
49 |
50 | UIStatusBarHidden
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/ios/Runner/Runner-Bridging-Header.h:
--------------------------------------------------------------------------------
1 | #import "GeneratedPluginRegistrant.h"
2 |
--------------------------------------------------------------------------------
/lib/main.dart:
--------------------------------------------------------------------------------
1 | import 'package:flex_color_scheme/flex_color_scheme.dart';
2 | import 'package:flutter/material.dart';
3 | import 'package:flutter_dotenv/flutter_dotenv.dart';
4 | import 'package:flutter_native_splash/flutter_native_splash.dart';
5 | import 'package:flutter_riverpod/flutter_riverpod.dart';
6 | import 'package:hive_flutter/hive_flutter.dart';
7 |
8 | import 'src/app_routes.dart';
9 | import 'src/common_widgets/error_screen.dart';
10 | import 'src/features/settings/data/providers/theme_provider.dart';
11 | import 'src/utils/contants.dart';
12 |
13 | void main() async {
14 | WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
15 | FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
16 | await dotenv.load(fileName: '.env');
17 | await Hive.initFlutter();
18 | await Hive.openBox(Constants.settingsStorageKey); // settings
19 | await Hive.openBox(Constants.authStorageKey); // auth
20 |
21 | // api getters
22 | // now hide splash screen
23 | FlutterNativeSplash.remove();
24 |
25 | runApp(const ProviderScope(child: MyApp()));
26 | }
27 |
28 | class MyApp extends ConsumerWidget {
29 | const MyApp({super.key});
30 |
31 | @override
32 | Widget build(BuildContext context, WidgetRef ref) {
33 | final theme = ref.watch(themeProvider);
34 |
35 | return MaterialApp(
36 | debugShowCheckedModeBanner: false,
37 | initialRoute: '/',
38 | routes: appRoutes,
39 | onGenerateRoute: (settings) => appGeneratedRoutes(settings),
40 | onUnknownRoute: (settings) => MaterialPageRoute(
41 | builder: (context) => ErrorScreen(
42 | name: settings.name,
43 | ),
44 | ),
45 | theme: FlexThemeData.light(scheme: theme.scheme).copyWith(
46 | bottomSheetTheme: const BottomSheetThemeData(
47 | backgroundColor: Colors.transparent,
48 | ),
49 | ),
50 | darkTheme: FlexThemeData.dark(scheme: theme.scheme).copyWith(
51 | bottomSheetTheme: const BottomSheetThemeData(
52 | backgroundColor: Colors.transparent,
53 | ),
54 | ),
55 | themeMode: theme.mode,
56 | );
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/lib/src/app_routes.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:page_transition/page_transition.dart';
3 |
4 | import 'common_widgets/error_screen.dart';
5 | import 'features/auth/ui/auth_screen.dart';
6 | import 'features/auth/ui/dashboard_screen.dart';
7 | import 'features/calculator/ui/calculator_screen.dart';
8 | import 'features/counter/ui/counter_screen.dart';
9 | import 'features/counter/ui/timer_screen.dart';
10 | import 'features/home/ui/home_screen.dart';
11 | import 'features/movies/ui/movies_paginated_screen.dart';
12 | import 'features/movies/ui/movies_screen.dart';
13 | import 'features/network_status/ui/network_status_screen.dart';
14 | import 'features/products/ui/products_screen.dart';
15 | import 'features/providers/ui/providers_screen.dart';
16 | import 'features/settings/ui/settings_screen.dart';
17 | import 'features/stopwatch/ui/stopwatch_screen.dart';
18 | import 'features/trivia/ui/trivia_screen.dart';
19 | import 'features/websockets/ui/websockets_screen.dart';
20 |
21 | final Map appRoutes = {
22 | HomeScreen.route: (context) => const HomeScreen(),
23 | ErrorScreen.route: (context) => ErrorScreen(),
24 | ProvidersScreen.route: (context) => const ProvidersScreen(),
25 | CalculatorScreen.route: (context) => const CalculatorScreen(),
26 | NetworkStatusScreen.route: (context) => const NetworkStatusScreen(),
27 | StopwatchScreen.route: (context) => const StopwatchScreen(),
28 | TriviaScreen.route: (context) => const TriviaScreen(),
29 | WebsocketsScreen.route: (context) => const WebsocketsScreen(),
30 | MoviesScreen.route: (context) => const MoviesScreen(),
31 | MoviesPaginatedScreen.route: (context) => const MoviesPaginatedScreen(),
32 | ProductsScreen.route: (context) => ProductsScreen(),
33 | SettingsScreen.route: (context) => const SettingsScreen(),
34 | AuthScreen.route: (context) => const AuthScreen(),
35 | DashboardScreen.route: (context) => const DashboardScreen(),
36 | };
37 |
38 | Route? appGeneratedRoutes(RouteSettings settings) {
39 | switch (settings.name) {
40 | case CounterScreen.route:
41 | return PageTransition(
42 | child: const CounterScreen(), type: PageTransitionType.bottomToTop);
43 | case TimerScreen.route:
44 | return PageTransition(
45 | child: const TimerScreen(), type: PageTransitionType.bottomToTop);
46 | default:
47 | break;
48 | }
49 |
50 | return null;
51 | }
52 |
--------------------------------------------------------------------------------
/lib/src/common_widgets/connectivity_warning.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/foundation.dart';
2 | import 'package:flutter/material.dart';
3 | import 'package:flutter_riverpod/flutter_riverpod.dart';
4 |
5 | import '../features/network_status/providers/network_status_provider.dart';
6 |
7 | class ConnectivityWarning extends ConsumerWidget {
8 | const ConnectivityWarning({super.key});
9 |
10 | @override
11 | Widget build(BuildContext context, WidgetRef ref) {
12 | if (kDebugMode) {
13 | print('ConnectivityWarning.build');
14 | }
15 |
16 | var network = ref.watch(networkAwareProvider);
17 |
18 | return network == NetworkStatus.off
19 | ? Container(
20 | padding: const EdgeInsets.all(16),
21 | height: 60,
22 | color: Colors.red.shade500,
23 | child: Row(
24 | children: [
25 | Icon(
26 | Icons.wifi_off,
27 | color: Colors.grey.shade100,
28 | ),
29 | const SizedBox(
30 | width: 8,
31 | ),
32 | Text(
33 | 'No internet connection',
34 | style: Theme.of(context)
35 | .textTheme
36 | .bodyMedium!
37 | .copyWith(color: Colors.grey.shade100),
38 | ),
39 | ],
40 | ),
41 | )
42 | : Container();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/lib/src/common_widgets/error_screen.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:hooks_riverpod/hooks_riverpod.dart';
3 |
4 | class ErrorScreen extends ConsumerWidget {
5 | String? name;
6 | ErrorScreen({super.key, this.name});
7 | static const route = '/error';
8 |
9 | @override
10 | Widget build(BuildContext context, WidgetRef ref) {
11 | return Scaffold(
12 | appBar: AppBar(
13 | title: const Text('Error'),
14 | ),
15 | body: Center(
16 | child: Column(
17 | children: [
18 | const Text('An error occurred'),
19 | name != null ? Text('$name') : Container(),
20 | ],
21 | ),
22 | ),
23 | );
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/lib/src/features/auth/data/enums/auth_status.dart:
--------------------------------------------------------------------------------
1 | enum AuthStatus {
2 | unauthenticated,
3 | authenticated,
4 | }
5 |
--------------------------------------------------------------------------------
/lib/src/features/auth/data/exceptions/login_exception.dart:
--------------------------------------------------------------------------------
1 | import 'package:dio/dio.dart';
2 |
3 | class LoginException implements Exception {
4 | String? message;
5 |
6 | LoginException({this.message});
7 |
8 | LoginException.fromDioError(DioError dioError) {
9 | switch (dioError.type) {
10 | case DioErrorType.cancel:
11 | message = 'Request to API server was cancelled';
12 | break;
13 | case DioErrorType.connectTimeout:
14 | message = 'Connection timeout with API server';
15 | break;
16 | case DioErrorType.other:
17 | message = 'Connection to API server fiailed due to internet connection';
18 | break;
19 | case DioErrorType.receiveTimeout:
20 | message = 'Received timeout in connection with API server';
21 | break;
22 | case DioErrorType.response:
23 | message = _handeError(dioError.response!.statusCode);
24 | break;
25 | case DioErrorType.sendTimeout:
26 | message = 'Send timeout in connection with API server';
27 | break;
28 | default:
29 | message = 'Something went wrong';
30 | break;
31 | }
32 | }
33 |
34 | String _handeError(statusCode) {
35 | switch (statusCode) {
36 | case 400:
37 | return 'Bad Request';
38 | case 404:
39 | return 'The requested resources was not found';
40 | case 500:
41 | return 'Internal Server Error';
42 | default:
43 | return 'Internal Server Error';
44 | }
45 | }
46 |
47 | @override
48 | String toString() => message.toString();
49 | }
50 |
--------------------------------------------------------------------------------
/lib/src/features/auth/data/models/auth_state.dart:
--------------------------------------------------------------------------------
1 | // ignore_for_file: public_member_api_docs, sort_constructors_first
2 | import '../enums/auth_status.dart';
3 | import 'user.dart';
4 |
5 | class AuthState {
6 | final String? accessToken;
7 | final User? user;
8 | final AuthStatus status;
9 | final String? errorMessage;
10 | final bool loading;
11 |
12 | bool get hasError => errorMessage != null && errorMessage!.isNotEmpty;
13 |
14 | AuthState({
15 | this.accessToken,
16 | this.user,
17 | this.status = AuthStatus.unauthenticated,
18 | this.errorMessage,
19 | this.loading = false,
20 | });
21 |
22 | AuthState copyWith({
23 | String? accessToken,
24 | User? user,
25 | AuthStatus? status,
26 | String? errorMessage,
27 | bool? loading,
28 | }) {
29 | return AuthState(
30 | accessToken: accessToken ?? this.accessToken,
31 | user: user ?? this.user,
32 | status: status ?? this.status,
33 | loading: loading ?? this.loading,
34 | errorMessage: errorMessage ?? this.errorMessage,
35 | );
36 | }
37 |
38 | factory AuthState.initial() {
39 | return AuthState(
40 | status: AuthStatus.unauthenticated,
41 | user: null,
42 | accessToken: null,
43 | errorMessage: null,
44 | loading: false,
45 | );
46 | }
47 |
48 | @override
49 | String toString() =>
50 | 'status $status accessToken $accessToken user ${user.toString()} ';
51 | }
52 |
--------------------------------------------------------------------------------
/lib/src/features/auth/data/models/login.dart:
--------------------------------------------------------------------------------
1 | class Login {
2 | final String? email;
3 | final String? password;
4 |
5 | const Login({
6 | this.email,
7 | this.password,
8 | });
9 |
10 | Login copyWith({
11 | String? email,
12 | String? password,
13 | }) {
14 | return Login(
15 | email: email ?? this.email,
16 | password: password ?? this.password,
17 | );
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/lib/src/features/auth/data/models/user.dart:
--------------------------------------------------------------------------------
1 | // ignore_for_file: public_member_api_docs, sort_constructors_first
2 | import 'dart:convert';
3 |
4 | class User {
5 | final String name;
6 | final String email;
7 | final String? avatar;
8 |
9 | User({required this.name, required this.email, this.avatar});
10 |
11 | @override
12 | String toString() => 'name $name email $email avatar $avatar';
13 |
14 | Map toMap() {
15 | return {
16 | 'name': name,
17 | 'email': email,
18 | 'avatar': avatar,
19 | };
20 | }
21 |
22 | factory User.fromMap(Map map) {
23 | return User(
24 | name: map['name'] as String,
25 | email: map['email'] as String,
26 | avatar: map['avatar'] != null ? map['avatar'] as String : null,
27 | );
28 | }
29 |
30 | String toJson() => json.encode(toMap());
31 |
32 | factory User.fromJson(String source) =>
33 | User.fromMap(json.decode(source) as Map);
34 | }
35 |
--------------------------------------------------------------------------------
/lib/src/features/auth/data/providers/auth_provider.dart:
--------------------------------------------------------------------------------
1 | import 'package:dio/dio.dart';
2 | import 'package:flutter_riverpod/flutter_riverpod.dart';
3 | import 'package:hive_flutter/hive_flutter.dart';
4 |
5 | import '../../../../utils/contants.dart';
6 | import '../enums/auth_status.dart';
7 | import '../exceptions/login_exception.dart';
8 | import '../models/auth_state.dart';
9 | import '../models/user.dart';
10 | import '../repositories/auth_repository.dart';
11 |
12 | final authNotifierProvider =
13 | StateNotifierProvider((ref) {
14 | final repo = ref.watch(authRepositoryProvider);
15 | return AuthStateNotifier(repo);
16 | });
17 |
18 | class AuthStateNotifier extends StateNotifier {
19 | final AuthRepository _repo;
20 |
21 | AuthStateNotifier(this._repo, [AuthState? state])
22 | : super(state ?? AuthState.initial()) {
23 | checkAuthStatus();
24 | }
25 |
26 | Future checkAuthStatus() async {
27 | // check storage for existing token/user
28 | final box = Hive.box(Constants.authStorageKey);
29 | final token = box.get('token');
30 | final user = box.get('user');
31 |
32 | // if authenticated, update state accordingly
33 | if ((token != null && token.toString().isNotEmpty) &&
34 | (user != null && user.toString().isNotEmpty)) {
35 | state = state.copyWith(
36 | status: AuthStatus.authenticated,
37 | user: User.fromJson(user.toString()),
38 | accessToken: token.toString(),
39 | );
40 |
41 | return;
42 | }
43 | state = state.copyWith(
44 | status: AuthStatus.unauthenticated,
45 | );
46 | }
47 |
48 | Future login({required String email, required String password}) async {
49 | try {
50 | state = state.copyWith(
51 | loading: true,
52 | errorMessage: '',
53 | );
54 |
55 | final token = await _repo.login(email: email, password: password);
56 |
57 | final user = User(email: email, name: email.split('@').first);
58 |
59 | final box = Hive.box(Constants.authStorageKey);
60 | await box.put('token', token);
61 | await box.put('user', user.toJson());
62 |
63 | state = state.copyWith(
64 | accessToken: token,
65 | user: user,
66 | status: AuthStatus.authenticated,
67 | errorMessage: '',
68 | );
69 | } on DioError catch (e) {
70 | final exc = LoginException.fromDioError(e);
71 | state = state.copyWith(
72 | errorMessage: exc.message,
73 | );
74 | } catch (e) {
75 | state = state.copyWith(
76 | errorMessage: e.toString(),
77 | );
78 | } finally {
79 | state = state.copyWith(
80 | loading: false,
81 | );
82 | }
83 | }
84 |
85 | Future logout() async {
86 | state = state.copyWith(
87 | loading: true,
88 | errorMessage: '',
89 | );
90 |
91 | // do some API stuff
92 | await Future.delayed(const Duration(milliseconds: 300));
93 |
94 | final box = Hive.box(Constants.authStorageKey);
95 | await box.delete('token');
96 | await box.delete('user');
97 |
98 | state = state.copyWith(
99 | user: null,
100 | accessToken: null,
101 | status: AuthStatus.unauthenticated,
102 | loading: false,
103 | );
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/lib/src/features/auth/data/repositories/auth_repository.dart:
--------------------------------------------------------------------------------
1 | import 'package:dio/dio.dart';
2 | import 'package:flutter_riverpod/flutter_riverpod.dart';
3 |
4 | import '../exceptions/login_exception.dart';
5 |
6 | abstract class AuthRepository {
7 | Future login({
8 | required String email,
9 | required String password,
10 | });
11 | }
12 |
13 | class ApiAuthRepository implements AuthRepository {
14 | final Dio _dio;
15 |
16 | ApiAuthRepository(this._dio);
17 |
18 | @override
19 | Future login(
20 | {required String email, required String password}) async {
21 | const url = 'https://reqres.in/api/login';
22 |
23 | try {
24 | final data = {
25 | 'email': email,
26 | 'password': password,
27 | };
28 |
29 | final response = await _dio.post(url, data: data);
30 |
31 | final token = response.data['token'] as String;
32 | return token;
33 | } on DioError catch (e) {
34 | throw LoginException(message: 'Unable to login');
35 | } catch (e) {
36 | throw Exception('Unable to login');
37 | }
38 | }
39 | }
40 |
41 | final authRepositoryProvider = Provider((ref) {
42 | return ApiAuthRepository(Dio());
43 | });
44 |
--------------------------------------------------------------------------------
/lib/src/features/auth/ui/auth_screen.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:hooks_riverpod/hooks_riverpod.dart';
3 |
4 | import '../data/enums/auth_status.dart';
5 | import '../data/providers/auth_provider.dart';
6 | import 'dashboard_screen.dart';
7 | import 'login_form.dart';
8 |
9 | class AuthScreen extends StatelessWidget {
10 | const AuthScreen({Key? key}) : super(key: key);
11 | static const route = '/auth';
12 |
13 | @override
14 | Widget build(BuildContext context) {
15 | return Consumer(
16 | builder: (context, ref, child) {
17 | final authStatus =
18 | ref.watch(authNotifierProvider.select((value) => value.status));
19 |
20 | return Container(
21 | child: authStatus == AuthStatus.unauthenticated
22 | ? const LoginForm()
23 | : authStatus == AuthStatus.authenticated
24 | ? const DashboardScreen()
25 | : const Center(
26 | child: CircularProgressIndicator(),
27 | ),
28 | );
29 | },
30 | );
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/lib/src/features/auth/ui/dashboard_screen.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:flutter_riverpod/flutter_riverpod.dart';
3 |
4 | import '../data/providers/auth_provider.dart';
5 |
6 | class DashboardScreen extends ConsumerWidget {
7 | const DashboardScreen({Key? key}) : super(key: key);
8 | static const route = '/dashboard';
9 |
10 | @override
11 | Widget build(BuildContext context, WidgetRef ref) {
12 | final auth = ref.watch(authNotifierProvider);
13 |
14 | return Scaffold(
15 | appBar: AppBar(
16 | title: const Text('Dashboard'),
17 | ),
18 | body: Center(
19 | child: Column(
20 | mainAxisAlignment: MainAxisAlignment.center,
21 | crossAxisAlignment: CrossAxisAlignment.center,
22 | children: [
23 | Text('Welcome back, ${auth.user?.name}'),
24 | Text('${auth.user?.email}'),
25 | const SizedBox(
26 | height: 20,
27 | ),
28 | ElevatedButton(
29 | onPressed: () {
30 | ref.read(authNotifierProvider.notifier).logout();
31 | },
32 | child: Text(auth.loading ? 'Logging Out' : 'Logout'),
33 | ),
34 | ],
35 | ),
36 | ),
37 | );
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/lib/src/features/calculator/data/models/calculator.dart:
--------------------------------------------------------------------------------
1 | class Calculator {
2 | final bool shouldAppend;
3 | final String equation;
4 | final String result;
5 |
6 | const Calculator({
7 | this.shouldAppend = true,
8 | this.equation = '0',
9 | this.result = '0',
10 | });
11 |
12 | Calculator copy({
13 | bool? shouldAppend,
14 | String? equation,
15 | String? result,
16 | }) =>
17 | Calculator(
18 | shouldAppend: shouldAppend ?? this.shouldAppend,
19 | equation: equation ?? this.equation,
20 | result: result ?? this.result,
21 | );
22 | }
23 |
--------------------------------------------------------------------------------
/lib/src/features/calculator/data/providers/calculator_provider.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:flutter_riverpod/flutter_riverpod.dart';
3 | import 'package:math_expressions/math_expressions.dart';
4 |
5 | import '../models/calculator.dart';
6 |
7 | class CalcColors {
8 | static const Color background1 = Color(0Xff22252d);
9 | static const Color background2 = Color(0xff292d36);
10 | static const Color background3 = Color(0xff272b33);
11 | static const Color operators = Color(0xfff57b7b);
12 | static const Color delete = Color(0xff26f4ce);
13 | static const Color numbers = Colors.white;
14 | }
15 |
16 | class Utils {
17 | static bool isOperator(String buttonText, {bool hasEquals = false}) {
18 | final operators = [
19 | '+',
20 | '-',
21 | '/',
22 | '÷',
23 | 'x',
24 | '.',
25 | if (hasEquals) ...['=']
26 | ];
27 |
28 | return operators.contains(buttonText);
29 | }
30 |
31 | static bool isOperatorAtEnd(String equation) {
32 | if (equation.isNotEmpty) {
33 | return Utils.isOperator(equation.substring(equation.length - 1));
34 | }
35 | return false;
36 | }
37 | }
38 |
39 | final calculatorProvider =
40 | StateNotifierProvider(
41 | (ref) => CalculatorNotifier());
42 |
43 | class CalculatorNotifier extends StateNotifier {
44 | CalculatorNotifier() : super(const Calculator());
45 |
46 | void append(String buttonText) {
47 | final equation = () {
48 | if (Utils.isOperator(buttonText) &&
49 | Utils.isOperatorAtEnd(state.equation)) {
50 | final newEquation =
51 | state.equation.substring(0, state.equation.length - 1);
52 |
53 | return newEquation + buttonText;
54 | } else if (state.shouldAppend) {
55 | return state.equation == '0' ? buttonText : state.equation + buttonText;
56 | }
57 |
58 | return Utils.isOperator(buttonText)
59 | ? state.equation + buttonText
60 | : buttonText;
61 | }();
62 |
63 | state = state.copy(equation: equation, shouldAppend: true);
64 | calculate();
65 | }
66 |
67 | void delete() {
68 | final equation = state.equation;
69 |
70 | if (equation.isNotEmpty) {
71 | final newEquation = equation.substring(0, equation.length - 1);
72 |
73 | if (newEquation.isEmpty) {
74 | reset();
75 | } else {
76 | state = state.copy(equation: newEquation);
77 | calculate();
78 | }
79 | }
80 | }
81 |
82 | void equals() {
83 | calculate();
84 | resetResult();
85 | }
86 |
87 | void calculate() {
88 | // replace illegal expressions
89 | final expression = state.equation.replaceAll('x', '*').replaceAll('÷', '/');
90 |
91 | try {
92 | final exp = Parser().parse(expression);
93 | final model = ContextModel();
94 |
95 | final result = '${exp.evaluate(EvaluationType.REAL, model)}';
96 | // copy current object with everything it had before, and set only results field
97 | state = state.copy(result: result);
98 | // ignore: empty_catches
99 | } catch (e) {}
100 | }
101 |
102 | void reset() {
103 | const equation = '0';
104 | const result = '0';
105 |
106 | state = state.copy(equation: equation, result: result);
107 | }
108 |
109 | void resetResult() {
110 | final equation = state.result;
111 |
112 | state = state.copy(equation: equation, shouldAppend: false);
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/lib/src/features/counter/providers/counter_provider.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter_riverpod/flutter_riverpod.dart';
2 |
3 | final counterProvider = StateNotifierProvider.autoDispose((ref) => Counter());
4 |
5 | class Counter extends StateNotifier {
6 | Counter() : super(0);
7 |
8 | void increment() => state++;
9 | }
10 |
11 | Stream numbers() =>
12 | Stream.periodic(const Duration(seconds: 1), (e) => e + 1).take(10);
13 |
--------------------------------------------------------------------------------
/lib/src/features/counter/providers/timer_provider.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter_riverpod/flutter_riverpod.dart';
2 |
3 | final counterProvider = StateNotifierProvider.autoDispose((ref) => Counter());
4 |
5 | class Counter extends StateNotifier {
6 | Counter() : super(0);
7 |
8 | void increment() => state++;
9 | }
10 |
11 | final limitCountProvider = StateProvider((ref) => 5);
12 |
13 | final streamProvider = StreamProvider((ref) {
14 | final int limit = ref.watch(limitCountProvider);
15 |
16 | return Stream.periodic(const Duration(seconds: 1), (number) => number + 1)
17 | .take(limit);
18 | });
19 |
--------------------------------------------------------------------------------
/lib/src/features/counter/ui/counter_screen.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/foundation.dart';
2 | import 'package:flutter/material.dart';
3 | import 'package:flutter_riverpod/flutter_riverpod.dart';
4 |
5 | import '../providers/counter_provider.dart';
6 |
7 | class CounterScreen extends StatelessWidget {
8 | const CounterScreen({super.key});
9 |
10 | static const route = '/counter';
11 |
12 | @override
13 | Widget build(BuildContext context) {
14 | if (kDebugMode) {
15 | print('CounterScreen.build');
16 | }
17 | return Scaffold(
18 | appBar: AppBar(
19 | title: const Text('Auto-Disposed Counter App'),
20 | ),
21 | body: Center(
22 | child: Column(
23 | mainAxisAlignment: MainAxisAlignment.center,
24 | crossAxisAlignment: CrossAxisAlignment.center,
25 | children: [
26 | const CounterLabel(),
27 | const CounterDisplay(),
28 | const SizedBox(
29 | height: 20,
30 | ),
31 | TimerCountdown(),
32 | ],
33 | ),
34 | ),
35 | floatingActionButton: const CounterIncrement(),
36 | );
37 | }
38 | }
39 |
40 | class CounterLabel extends ConsumerWidget {
41 | const CounterLabel({
42 | super.key,
43 | });
44 |
45 | @override
46 | Widget build(BuildContext context, WidgetRef ref) {
47 | if (kDebugMode) {
48 | print('CounterLabel.build');
49 | }
50 | return const Text('The count is: ');
51 | }
52 | }
53 |
54 | class CounterDisplay extends ConsumerWidget {
55 | const CounterDisplay({super.key});
56 |
57 | @override
58 | Widget build(BuildContext context, WidgetRef ref) {
59 | if (kDebugMode) {
60 | print('CounterDisplay.build');
61 | }
62 |
63 | final counter = ref.watch(counterProvider);
64 |
65 | return Text('$counter');
66 | }
67 | }
68 |
69 | class CounterIncrement extends ConsumerWidget {
70 | const CounterIncrement({super.key});
71 |
72 | @override
73 | Widget build(BuildContext context, WidgetRef ref) {
74 | if (kDebugMode) {
75 | print('CounterIncrement.build');
76 | }
77 |
78 | return FloatingActionButton(
79 | onPressed: () {
80 | ref.read(counterProvider.notifier).increment();
81 | },
82 | child: const Icon(Icons.add),
83 | );
84 | }
85 | }
86 |
87 | class TimerCountdown extends ConsumerWidget {
88 | TimerCountdown({super.key});
89 |
90 | final _numbers = numbers();
91 |
92 | @override
93 | Widget build(BuildContext context, WidgetRef ref) {
94 | if (kDebugMode) {
95 | print('TimerCountdown.build');
96 | }
97 |
98 | return StreamBuilder(
99 | stream: _numbers,
100 | builder: (context, snapshot) {
101 | switch (snapshot.connectionState) {
102 | case ConnectionState.none:
103 | case ConnectionState.waiting:
104 | return const Center(
105 | child: CircularProgressIndicator(),
106 | );
107 | case ConnectionState.active:
108 | return Text('Countdown: ${snapshot.data}');
109 | case ConnectionState.done:
110 | return SelectableText('Done at: ${snapshot.data}');
111 | default:
112 | return Container();
113 | }
114 | },
115 | );
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/lib/src/features/counter/ui/timer_screen.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/foundation.dart';
2 | import 'package:flutter/material.dart';
3 | import 'package:flutter_riverpod/flutter_riverpod.dart';
4 |
5 | import '../../../utils/context_snackbar.dart';
6 | import '../providers/timer_provider.dart';
7 |
8 | class TimerScreen extends ConsumerWidget {
9 | const TimerScreen({Key? key}) : super(key: key);
10 |
11 | static const route = '/timer';
12 |
13 | @override
14 | Widget build(BuildContext context, WidgetRef ref) {
15 | if (kDebugMode) {
16 | print('TimerScreen.build');
17 | }
18 |
19 | return Scaffold(
20 | appBar: AppBar(
21 | title: const Text('Auto-Disposed Timer App w/ Limit'),
22 | ),
23 | body: Center(
24 | child: Column(
25 | mainAxisAlignment: MainAxisAlignment.center,
26 | crossAxisAlignment: CrossAxisAlignment.center,
27 | children: const [
28 | Text('The count is: '),
29 | SizedBox(
30 | height: 20,
31 | ),
32 | TimerDisplay(),
33 | SizedBox(
34 | height: 20,
35 | ),
36 | TimerCountdown(),
37 | SizedBox(
38 | height: 20,
39 | ),
40 | ],
41 | ),
42 | ),
43 | floatingActionButton: const TimerIncrement(),
44 | );
45 | }
46 | }
47 |
48 | class TimerDisplay extends ConsumerWidget {
49 | const TimerDisplay({super.key});
50 |
51 | @override
52 | Widget build(BuildContext context, WidgetRef ref) {
53 | if (kDebugMode) {
54 | print('TimerDisplay.build');
55 | }
56 |
57 | final counter = ref.watch(counterProvider);
58 | final int limit = ref.watch(limitCountProvider);
59 |
60 | // ref.listen>(
61 | // counterProvider,
62 | // (_, state) => state.showSnackBarOnError(context),
63 | // );
64 |
65 | ref.listen(counterProvider, (prev, next) {
66 | int count = int.parse(next.toString());
67 |
68 | if (count >= limit) {
69 | ScaffoldMessenger.of(context).showSnackBar(
70 | SnackBar(content: Text('Exceeds limit of $limit')),
71 | );
72 | }
73 | });
74 |
75 | return Text('$counter');
76 | }
77 | }
78 |
79 | class TimerIncrement extends ConsumerWidget {
80 | const TimerIncrement({super.key});
81 |
82 | @override
83 | Widget build(BuildContext context, WidgetRef ref) {
84 | if (kDebugMode) {
85 | print('TimerIncrement.build');
86 | }
87 |
88 | return FloatingActionButton(
89 | onPressed: () {
90 | ref.read(counterProvider.notifier).increment();
91 | },
92 | child: const Icon(Icons.add),
93 | );
94 | }
95 | }
96 |
97 | class TimerCountdown extends ConsumerWidget {
98 | const TimerCountdown({super.key});
99 |
100 | @override
101 | Widget build(BuildContext context, WidgetRef ref) {
102 | if (kDebugMode) {
103 | print('TimerCountdown.build');
104 | }
105 |
106 | final stream = ref.watch(streamProvider);
107 | final int limit = ref.watch(limitCountProvider);
108 |
109 | ref.listen(streamProvider, (prev, next) {
110 | if (next.value! >= limit) {
111 | context.showSnackBar(context, message: 'Timer done at $limit');
112 | }
113 | });
114 |
115 | return stream.when(
116 | data: (data) => Text('Stream Provider: $data'),
117 | error: (error, stack) => Text('Error: $error'),
118 | loading: () => const CircularProgressIndicator(),
119 | );
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/lib/src/features/home/data/models/entry.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | class Entry {
4 | String title;
5 | Icon icon;
6 | String route;
7 |
8 | Entry({required this.title, required this.icon, required this.route});
9 | }
10 |
--------------------------------------------------------------------------------
/lib/src/features/home/data/providers/home_provider.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:hooks_riverpod/hooks_riverpod.dart';
3 | import '../../../auth/ui/auth_screen.dart';
4 | import '../../../calculator/ui/calculator_screen.dart';
5 | import '../../../counter/ui/counter_screen.dart';
6 |
7 | import '../../../counter/ui/timer_screen.dart';
8 | import '../../../movies/ui/movies_paginated_screen.dart';
9 | import '../../../movies/ui/movies_screen.dart';
10 | import '../../../network_status/ui/network_status_screen.dart';
11 | import '../../../products/ui/products_screen.dart';
12 | import '../../../providers/ui/providers_screen.dart';
13 | import '../../../settings/ui/settings_screen.dart';
14 | import '../../../stopwatch/ui/stopwatch_screen.dart';
15 | import '../../../trivia/ui/trivia_screen.dart';
16 | import '../../../websockets/ui/websockets_screen.dart';
17 | import '../models/entry.dart';
18 |
19 | final homeMenuEntriesProvider = StateProvider>((ref) {
20 | return [
21 | Entry(
22 | title: 'Providers',
23 | icon: const Icon(Icons.shopping_cart),
24 | route: ProvidersScreen.route,
25 | ),
26 | Entry(
27 | title: 'Counter App',
28 | icon: const Icon(Icons.timer),
29 | route: CounterScreen.route,
30 | ),
31 | Entry(
32 | title: 'Timer with Alert',
33 | icon: const Icon(Icons.timer_10_select),
34 | route: TimerScreen.route,
35 | ),
36 | Entry(
37 | title: 'Calculator',
38 | icon: const Icon(Icons.calculate),
39 | route: CalculatorScreen.route,
40 | ),
41 | Entry(
42 | title: 'Network Status',
43 | icon: const Icon(Icons.network_check),
44 | route: NetworkStatusScreen.route,
45 | ),
46 | Entry(
47 | title: 'Stopwatch',
48 | icon: const Icon(Icons.timelapse_rounded),
49 | route: StopwatchScreen.route,
50 | ),
51 | Entry(
52 | title: 'Trivia',
53 | icon: const Icon(Icons.question_answer),
54 | route: TriviaScreen.route,
55 | ),
56 | Entry(
57 | title: 'Websockets',
58 | icon: const Icon(Icons.wifi_tethering),
59 | route: WebsocketsScreen.route,
60 | ),
61 | Entry(
62 | title: 'Movies',
63 | icon: const Icon(Icons.movie),
64 | route: MoviesScreen.route,
65 | ),
66 | Entry(
67 | title: 'Movies (Paginated)',
68 | icon: const Icon(Icons.list),
69 | route: MoviesPaginatedScreen.route,
70 | ),
71 | Entry(
72 | title: 'Products (Pagination via StateNotifier)',
73 | icon: const Icon(Icons.shopping_cart),
74 | route: ProductsScreen.route,
75 | ),
76 | Entry(
77 | title: 'Settings',
78 | icon: const Icon(Icons.settings),
79 | route: SettingsScreen.route,
80 | ),
81 | Entry(
82 | title: 'Auth',
83 | icon: const Icon(Icons.home),
84 | route: AuthScreen.route,
85 | ),
86 | ];
87 | });
88 |
--------------------------------------------------------------------------------
/lib/src/features/home/ui/home_screen.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:hooks_riverpod/hooks_riverpod.dart';
3 | import '../../../common_widgets/connectivity_warning.dart';
4 | import '../../../utils/contants.dart';
5 | import '../data/providers/home_provider.dart';
6 |
7 | class HomeScreen extends ConsumerWidget {
8 | const HomeScreen({super.key});
9 | static const route = '/';
10 |
11 | @override
12 | Widget build(BuildContext context, WidgetRef ref) {
13 | final homeMenuEntries = ref.watch(homeMenuEntriesProvider);
14 |
15 | return Scaffold(
16 | appBar: AppBar(
17 | title: const Text(Constants.appName),
18 | ),
19 | body: ListView(
20 | children: [
21 | const ConnectivityWarning(),
22 | Column(
23 | children: homeMenuEntries
24 | .map(
25 | (item) => ListTile(
26 | title: Text(item.title),
27 | leading: item.icon,
28 | trailing: const Icon(Icons.chevron_right),
29 | onTap: () => Navigator.pushNamed(context, item.route),
30 | ),
31 | )
32 | .toList(),
33 | ),
34 | ],
35 | ),
36 | );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/lib/src/features/movies/data/environment_config.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter_dotenv/flutter_dotenv.dart';
2 | import 'package:flutter_riverpod/flutter_riverpod.dart';
3 |
4 | class EnvironmentConfig {
5 | // we add the api key by running 'flutter run --dart-define=movieApiKey=MYKEY
6 | // final movieApiKey = const String.fromEnvironment('movieKey');
7 |
8 | // or get it from the .env file
9 | final movieApiKey = dotenv.env['MOVIEDB_KEY'];
10 | }
11 |
12 | final environmentConfigProvider =
13 | Provider((ref) => EnvironmentConfig());
14 |
--------------------------------------------------------------------------------
/lib/src/features/movies/data/exceptions/movies_exception.dart:
--------------------------------------------------------------------------------
1 | import 'package:dio/dio.dart';
2 |
3 | class MoviesException implements Exception {
4 | String? message;
5 |
6 | MoviesException.fromDioError(DioError dioError) {
7 | switch (dioError.type) {
8 | case DioErrorType.cancel:
9 | message = 'Request to API server was cancelled';
10 | break;
11 | case DioErrorType.connectTimeout:
12 | message = 'Connection timeout with API server';
13 | break;
14 | case DioErrorType.other:
15 | message = 'Connection to API server fiailed due to internet connection';
16 | break;
17 | case DioErrorType.receiveTimeout:
18 | message = 'Received timeout in connection with API server';
19 | break;
20 | case DioErrorType.response:
21 | message = _handeError(dioError.response!.statusCode);
22 | break;
23 | case DioErrorType.sendTimeout:
24 | message = 'Send timeout in connection with API server';
25 | break;
26 | default:
27 | message = 'Something went wrong';
28 | break;
29 | }
30 | }
31 |
32 | String _handeError(statusCode) {
33 | switch (statusCode) {
34 | case 400:
35 | return 'Bad Request';
36 | case 404:
37 | return 'The requested resources was not found';
38 | case 500:
39 | return 'Internal Server Error';
40 | default:
41 | return 'Internal Server Error';
42 | }
43 | }
44 |
45 | @override
46 | String toString() => message.toString();
47 | }
48 |
--------------------------------------------------------------------------------
/lib/src/features/movies/data/models/movie.dart:
--------------------------------------------------------------------------------
1 | // ignore_for_file: public_member_api_docs, sort_constructors_first
2 | import 'dart:convert';
3 |
4 | class Movie {
5 | final String title;
6 | final String image;
7 |
8 | Movie({
9 | required this.title,
10 | required this.image,
11 | });
12 |
13 | String get fullImageUrl => 'https://image.tmdb.org/t/p/w500$image';
14 |
15 | Movie copyWith({
16 | String? title,
17 | String? image,
18 | }) {
19 | return Movie(
20 | title: title ?? this.title,
21 | image: image ?? this.image,
22 | );
23 | }
24 |
25 | Map toMap() {
26 | return {
27 | 'title': title,
28 | 'image': image,
29 | };
30 | }
31 |
32 | factory Movie.fromMap(Map map) {
33 | return Movie(
34 | title: map['title'] as String,
35 | image: map['poster_path'] as String,
36 | );
37 | }
38 |
39 | String toJson() => json.encode(toMap());
40 |
41 | factory Movie.fromJson(String source) =>
42 | Movie.fromMap(json.decode(source) as Map);
43 |
44 | @override
45 | String toString() => 'Movie(title: $title, image: $image)';
46 |
47 | @override
48 | bool operator ==(covariant Movie other) {
49 | if (identical(this, other)) return true;
50 |
51 | return other.title == title && other.image == image;
52 | }
53 |
54 | @override
55 | int get hashCode => title.hashCode ^ image.hashCode;
56 | }
57 |
--------------------------------------------------------------------------------
/lib/src/features/movies/data/models/movie_pagination.dart:
--------------------------------------------------------------------------------
1 | import 'dart:convert';
2 |
3 | import 'package:collection/collection.dart';
4 |
5 | import 'movie.dart';
6 |
7 | class MoviePagination {
8 | final List movies;
9 | final int page;
10 | final String errorMessage;
11 |
12 | MoviePagination.initial()
13 | : movies = [],
14 | page = 1,
15 | errorMessage = '';
16 |
17 | bool get refreshError => errorMessage != '' && movies.length <= 20;
18 |
19 | MoviePagination({
20 | required this.movies,
21 | required this.page,
22 | required this.errorMessage,
23 | });
24 |
25 | MoviePagination copyWith({
26 | List? movies,
27 | int? page,
28 | String? errorMessage,
29 | }) {
30 | return MoviePagination(
31 | movies: movies ?? this.movies,
32 | page: page ?? this.page,
33 | errorMessage: errorMessage ?? this.errorMessage,
34 | );
35 | }
36 |
37 | Map toMap() {
38 | return {
39 | 'movies': movies.map((x) => x.toMap()).toList(),
40 | 'page': page,
41 | 'errorMessage': errorMessage,
42 | };
43 | }
44 |
45 | factory MoviePagination.fromMap(Map map) {
46 | return MoviePagination(
47 | movies: List.from(
48 | (map['movies'] as List).map(
49 | (x) => Movie.fromMap(x as Map),
50 | ),
51 | ),
52 | page: map['page'] as int,
53 | errorMessage: map['errorMessage'] as String,
54 | );
55 | }
56 |
57 | String toJson() => json.encode(toMap());
58 |
59 | factory MoviePagination.fromJson(String source) =>
60 | MoviePagination.fromMap(json.decode(source) as Map);
61 |
62 | @override
63 | String toString() =>
64 | 'MoviePagination(movies: $movies, page: $page, errorMessage: $errorMessage)';
65 |
66 | @override
67 | bool operator ==(covariant MoviePagination other) {
68 | if (identical(this, other)) return true;
69 | final listEquals = const DeepCollectionEquality().equals;
70 |
71 | return listEquals(other.movies, movies) &&
72 | other.page == page &&
73 | other.errorMessage == errorMessage;
74 | }
75 |
76 | @override
77 | int get hashCode => movies.hashCode ^ page.hashCode ^ errorMessage.hashCode;
78 | }
79 |
--------------------------------------------------------------------------------
/lib/src/features/movies/data/providers/movies_provider.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter_riverpod/flutter_riverpod.dart';
2 |
3 | import '../exceptions/movies_exception.dart';
4 | import '../models/movie.dart';
5 | import '../models/movie_pagination.dart';
6 | import '../repositories/movie_repository.dart';
7 |
8 | final moviesFutureProvider =
9 | FutureProvider.autoDispose>((ref) async {
10 | ref.maintainState = true;
11 |
12 | final movieService = ref.watch(movieServiceProvider);
13 | final movies = await movieService.getMovies();
14 | return movies;
15 | });
16 |
17 | // add pagination
18 | final moviesPaginationNotifierProvider = StateNotifierProvider((ref) {
19 | final movieService = ref.read(movieServiceProvider);
20 |
21 | return MoviePaginationNotifier(movieService);
22 | });
23 |
24 | class MoviePaginationNotifier extends StateNotifier {
25 | final MovieRepository _service;
26 |
27 | MoviePaginationNotifier(
28 | this._service, [
29 | MoviePagination? state,
30 | ]) : super(state ?? MoviePagination.initial()) {
31 | getMovies();
32 | }
33 |
34 | Future getMovies() async {
35 | try {
36 | final movies = await _service.getMovies(state.page);
37 |
38 | state = state
39 | .copyWith(movies: [...state.movies, ...movies], page: state.page + 1);
40 | } on MoviesException catch (e) {
41 | state = state.copyWith(errorMessage: e.message);
42 | }
43 | }
44 |
45 | void handleScrollWithIndex(int index) {
46 | final itemPosition = index + 1;
47 | final requestMoreData = itemPosition % 20 == 0 && itemPosition != 0;
48 |
49 | final pageToRequest = itemPosition ~/ 20;
50 |
51 | if (requestMoreData && pageToRequest + 1 >= state.page) {
52 | getMovies();
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/lib/src/features/movies/data/repositories/movie_repository.dart:
--------------------------------------------------------------------------------
1 | import 'package:dio/dio.dart';
2 | import 'package:flutter_riverpod/flutter_riverpod.dart';
3 |
4 | import '../environment_config.dart';
5 | import '../exceptions/movies_exception.dart';
6 | import '../models/movie.dart';
7 |
8 | const String moviesUrl = 'https://api.themoviedb.org/3/movie';
9 |
10 | final movieServiceProvider = Provider((ref) {
11 | final config = ref.watch(environmentConfigProvider);
12 |
13 | return MovieRepository(config, Dio());
14 | });
15 |
16 | class MovieRepository {
17 | final Dio _dio;
18 | final EnvironmentConfig _environmentConfig;
19 |
20 | MovieRepository(this._environmentConfig, this._dio);
21 |
22 | Future> getMovies([int page = 1]) async {
23 | try {
24 | final url =
25 | '$moviesUrl/popular?api_key=${_environmentConfig.movieApiKey}&language=en-US&page=$page';
26 | final response = await _dio.get(url);
27 |
28 | final results =
29 | List