Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .flutter-plugins
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This is a generated file; do not edit or check into version control.
flutter_secure_storage=C:\\Users\\Oguzhan\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\flutter_secure_storage-8.0.0\\
flutter_secure_storage_linux=C:\\Users\\Oguzhan\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\flutter_secure_storage_linux-1.1.3\\
flutter_secure_storage_macos=C:\\Users\\Oguzhan\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\flutter_secure_storage_macos-3.0.0\\
flutter_secure_storage_web=C:\\Users\\Oguzhan\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\flutter_secure_storage_web-1.1.1\\
flutter_secure_storage_windows=C:\\Users\\Oguzhan\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\flutter_secure_storage_windows-2.0.0\\
path_provider=C:\\Users\\Oguzhan\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\path_provider-2.0.14\\
path_provider_android=C:\\Users\\Oguzhan\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\path_provider_android-2.0.25\\
path_provider_foundation=C:\\Users\\Oguzhan\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\path_provider_foundation-2.2.2\\
path_provider_linux=C:\\Users\\Oguzhan\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\path_provider_linux-2.1.10\\
path_provider_windows=C:\\Users\\Oguzhan\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\path_provider_windows-2.1.5\\
shared_preferences=C:\\Users\\Oguzhan\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\shared_preferences-2.1.0\\
shared_preferences_android=C:\\Users\\Oguzhan\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\shared_preferences_android-2.1.2\\
shared_preferences_foundation=C:\\Users\\Oguzhan\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\shared_preferences_foundation-2.2.1\\
shared_preferences_linux=C:\\Users\\Oguzhan\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\shared_preferences_linux-2.2.0\\
shared_preferences_web=C:\\Users\\Oguzhan\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\shared_preferences_web-2.1.0\\
shared_preferences_windows=C:\\Users\\Oguzhan\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\shared_preferences_windows-2.2.0\\
1 change: 1 addition & 0 deletions .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_secure_storage","path":"C:\\\\Users\\\\Oguzhan\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_secure_storage-8.0.0\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"C:\\\\Users\\\\Oguzhan\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.2.2\\\\","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"C:\\\\Users\\\\Oguzhan\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_foundation-2.2.1\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"flutter_secure_storage","path":"C:\\\\Users\\\\Oguzhan\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_secure_storage-8.0.0\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_android","path":"C:\\\\Users\\\\Oguzhan\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_android-2.0.25\\\\","native_build":true,"dependencies":[]},{"name":"shared_preferences_android","path":"C:\\\\Users\\\\Oguzhan\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_android-2.1.2\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"flutter_secure_storage_macos","path":"C:\\\\Users\\\\Oguzhan\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_secure_storage_macos-3.0.0\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"C:\\\\Users\\\\Oguzhan\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.2.2\\\\","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"C:\\\\Users\\\\Oguzhan\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_foundation-2.2.1\\\\","native_build":true,"dependencies":[]}],"linux":[{"name":"flutter_secure_storage_linux","path":"C:\\\\Users\\\\Oguzhan\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_secure_storage_linux-1.1.3\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_linux","path":"C:\\\\Users\\\\Oguzhan\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_linux-2.1.10\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"C:\\\\Users\\\\Oguzhan\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_linux-2.2.0\\\\","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"flutter_secure_storage_windows","path":"C:\\\\Users\\\\Oguzhan\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_secure_storage_windows-2.0.0\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_windows","path":"C:\\\\Users\\\\Oguzhan\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_windows-2.1.5\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"C:\\\\Users\\\\Oguzhan\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_windows-2.2.0\\\\","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"flutter_secure_storage_web","path":"C:\\\\Users\\\\Oguzhan\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_secure_storage_web-1.1.1\\\\","dependencies":[]},{"name":"shared_preferences_web","path":"C:\\\\Users\\\\Oguzhan\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_web-2.1.0\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_secure_storage","dependencies":["flutter_secure_storage_linux","flutter_secure_storage_macos","flutter_secure_storage_web","flutter_secure_storage_windows"]},{"name":"flutter_secure_storage_linux","dependencies":[]},{"name":"flutter_secure_storage_macos","dependencies":[]},{"name":"flutter_secure_storage_web","dependencies":[]},{"name":"flutter_secure_storage_windows","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_foundation","shared_preferences_linux","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_foundation","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2023-04-26 18:16:17.907544","version":"3.7.11"}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# Files and directories created by pub
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
build/
# If you're building an application, you may want to check-in your pubspec.lock
Expand All @@ -19,3 +21,5 @@ doc/api/
*.js_
*.js.deps
*.js.map
*.env
*env.g.dart
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ android {
applicationId "com.example.chatgpt_flutter_case"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion flutter.minSdkVersion
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
3 changes: 3 additions & 0 deletions lib/core/constants/constants_shelf.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export 'global_variables.dart';
export 'shared_preferences_keys.dart';
export 'string_constants.dart';
11 changes: 11 additions & 0 deletions lib/core/constants/global_variables.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import '../core_shelf.dart';
import '../locator.dart';

class GVariables {
static final navigator = NavigationService.instance;
static final context = NavigationService.instance.navigatorKey.currentContext!;
static SPService spService = getIt<SPService>();
static final DialogService dialogService = DialogService();
static final OpenAIService openAIService = OpenAIService();
static final SecureStorage secureStorage = SecureStorage();
}
3 changes: 3 additions & 0 deletions lib/core/constants/shared_preferences_keys.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class SPKeys {
static const isDark = 'isDark';
}
3 changes: 3 additions & 0 deletions lib/core/constants/string_constants.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class StringConstants {
static String infoText = 'We’ve trained a model called ChatGPT which interacts in a conversational way.';
}
5 changes: 5 additions & 0 deletions lib/core/core_shelf.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export 'constants/constants_shelf.dart';
export 'providers/providers_shelf.dart';
export 'theme/theme_shelf.dart';
export 'services/services_shelf.dart';
export 'widgets/widgets_shelf.dart';
26 changes: 26 additions & 0 deletions lib/core/init/helpers/utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter/services.dart';

import '../../core_shelf.dart';

class Utils {
static final Utils _instance = Utils();
static Utils get instance => _instance;

void setSystemUi(bool isDark) {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarBrightness: isDark ? Brightness.light : Brightness.dark,
statusBarIconBrightness: isDark ? Brightness.dark : Brightness.light,
systemNavigationBarColor: Color(isDark ? 0xffffff : 0xff121212),
statusBarColor: Color(isDark ? 0xff16151A : 0xffF6F8FA),
systemNavigationBarIconBrightness: isDark ? Brightness.dark : Brightness.light,
),
);
}

Future<void> onThemeChanged(bool isDark, ThemeProvider themeNotifier) async {
Utils.instance.setSystemUi(isDark);
isDark ? themeNotifier.theme = getDarkTheme() : themeNotifier.theme = getLightTheme();
await GVariables.spService.setIsDark(isDark);
}
}
8 changes: 8 additions & 0 deletions lib/core/locator.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'package:chatgpt_flutter_case/core/services/locale_services/sp_service.dart';
import 'package:get_it/get_it.dart';

GetIt getIt = GetIt.instance;

void setupLocators() {
getIt.registerLazySingleton(() => SPService());
}
52 changes: 52 additions & 0 deletions lib/core/models/message_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
class MessageModel {
final String message;
final String sender;
final DateTime time;

MessageModel({
required this.message,
required this.sender,
required this.time,
});

factory MessageModel.fromJson(Map<String, dynamic> json) {
return MessageModel(
message: json['message'],
sender: json['sender'],
time: DateTime.parse(json['time']),
);
}

Map<String, dynamic> toJson() {
return {
'message': message,
'sender': sender,
'time': time.toIso8601String(),
};
}
}

class ConversationModel {
List<MessageModel>? messages;

ConversationModel({
this.messages,
});

ConversationModel.fromJson(Map<String, dynamic> json) {
if (json['messages'] != null) {
messages = <MessageModel>[];
json['messages'].forEach((v) {
messages?.add(MessageModel.fromJson(v));
});
}
}

Map<String, dynamic> toJson() {
final data = <String, dynamic>{};
if (messages != null) {
data['messages'] = messages?.map((v) => v.toJson()).toList();
}
return data;
}
}
28 changes: 28 additions & 0 deletions lib/core/providers/chat_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:chatgpt_flutter_case/core/models/message_model.dart';
import 'package:flutter/material.dart';

class ChatProvider extends ChangeNotifier {
ConversationModel _conversationModel = ConversationModel(messages: []);
ConversationModel get conversationModel => _conversationModel;

bool _awaitingResponse = false;
bool get awaitingResponse => _awaitingResponse;

bool _shouldAnimate = true;
bool get shouldAnimate => _shouldAnimate;

void insertMessage(MessageModel message) {
_conversationModel.messages!.insert(0, message);
notifyListeners();
}

void setAwaitingResponse(bool value) {
_awaitingResponse = value;
notifyListeners();
}

void setShouldAnimate(bool value) {
_shouldAnimate = value;
notifyListeners();
}
}
26 changes: 26 additions & 0 deletions lib/core/providers/provider_list.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:chatgpt_flutter_case/core/providers/chat_provider.dart';
import 'package:chatgpt_flutter_case/core/providers/theme_provider.dart';
import 'package:provider/provider.dart';
import 'package:provider/single_child_widget.dart';

import '../constants/global_variables.dart';

class ApplicationProvider {
static ApplicationProvider? _instance;
static ApplicationProvider? get instance {
_instance ??= ApplicationProvider._init();
return _instance;
}

ApplicationProvider._init();

List<SingleChildWidget> dependItems = [
ChangeNotifierProvider(
create: (context) => ThemeProvider(),
),
ChangeNotifierProvider(
create: (context) => ChatProvider(),
),
Provider.value(value: GVariables.navigator)
];
}
3 changes: 3 additions & 0 deletions lib/core/providers/providers_shelf.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export 'provider_list.dart';
export 'theme_provider.dart';
import 'package:provider/provider.dart';
44 changes: 44 additions & 0 deletions lib/core/providers/theme_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import 'package:chatgpt_flutter_case/core/constants/global_variables.dart';
import 'package:flutter/material.dart';

import '../theme/dark_theme.dart';
import '../theme/light_theme.dart';

class ThemeProvider with ChangeNotifier {
ThemeData _themeData = getLightTheme();
static final ThemeProvider _instance = ThemeProvider();
static ThemeProvider get instance => _instance;

ThemeData get theme => _instance._themeData;

set theme(ThemeData themeData) {
_instance._themeData = themeData;
GVariables.spService.setIsDark(theme == getDarkTheme());
notifyListeners();
}

Future<void> fetchLocale() async {
var isDark = GVariables.spService.getIsDark();
if (!isDark) {
_instance._themeData = getLightTheme();
_themeData = getLightTheme();
} else {
_instance._themeData = getDarkTheme();
_themeData = getDarkTheme();
}
notifyListeners();
}

changeTheme() {
if (_instance.theme == getDarkTheme()) {
_instance.theme = getLightTheme();
} else {
_instance.theme = getDarkTheme();
}
notifyListeners();
}

bool isDark() {
return _instance.theme == getDarkTheme();
}
}
16 changes: 16 additions & 0 deletions lib/core/services/locale_services/dialog_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:chatgpt_flutter_case/core/widgets/settings_view/settings_view.dart';
import 'package:flutter/material.dart';

class DialogService {
void showBottomSheet(
BuildContext context,
) {
showModalBottomSheet(
context: context,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
builder: (context) => const SettingsView(),
);
}
}
4 changes: 4 additions & 0 deletions lib/core/services/locale_services/locale_service_shelf.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export 'dialog_service.dart';
export 'navigation_service.dart';
export 'sp_service.dart';
export 'secure_storage.dart';
32 changes: 32 additions & 0 deletions lib/core/services/locale_services/navigation_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:flutter/material.dart';

class NavigationService {
static final NavigationService _instance = NavigationService._init();
static NavigationService get instance => _instance;

NavigationService._init();

GlobalKey<NavigatorState> navigatorKey = GlobalKey();
// ignore: prefer_function_declarations_over_variables
final removeAllOldRoutes = (route) => false;

Future<void> push({
required Widget route,
}) async {
await navigatorKey.currentState?.push(MaterialPageRoute(builder: (context) => route));
}

Future<void> pushAndRemoveUntil({required Widget route}) async {
await navigatorKey.currentState
?.pushAndRemoveUntil(MaterialPageRoute(builder: (context) => route), (route) => false);
}

void pop<T>({T? result}) {
return navigatorKey.currentState?.pop(result);
}

bool canPop() {
final NavigatorState? navigator = Navigator.maybeOf(navigatorKey.currentState!.context);
return navigator != null && navigator.canPop();
}
}
40 changes: 40 additions & 0 deletions lib/core/services/locale_services/secure_storage.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'dart:convert';

import 'package:chatgpt_flutter_case/core/models/message_model.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';

class SecureStorage {
FlutterSecureStorage get getStorage {
// ignore: no_leading_underscores_for_local_identifiers
AndroidOptions _getAndroidOptions() => const AndroidOptions(
encryptedSharedPreferences: true,
);
return FlutterSecureStorage(aOptions: _getAndroidOptions());
}

Future<void> saveMessage(ConversationModel messages) async {
final storage = getStorage;
final messageList = await storage.read(key: 'messages');
if (messageList == null) {
await storage.write(key: 'messages', value: jsonEncode([messages.toJson()]));
} else {
await storage.write(key: 'messages', value: '$messageList,${jsonEncode([messages.toJson()])}');
}
}

Future<List<ConversationModel>> getMessages() async {
final storage = getStorage;
final messageList = await storage.read(key: 'messages');
if (messageList == null) {
return [];
} else {
final messageListDecoded = jsonDecode(messageList).cast<Map<String, dynamic>>().toList();
return List.generate(messageListDecoded.length, (index) => ConversationModel.fromJson(messageListDecoded[index]));
}
}

Future<void> clearMessages() async {
final storage = getStorage;
await storage.delete(key: 'messages');
}
}
17 changes: 17 additions & 0 deletions lib/core/services/locale_services/sp_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:chatgpt_flutter_case/core/constants/shared_preferences_keys.dart';
import 'package:shared_preferences/shared_preferences.dart';

class SPService {
late SharedPreferences prefs;
Future<void> init() async {
prefs = await SharedPreferences.getInstance();
}

Future<bool> setIsDark(bool isDark) async {
return prefs.setBool(SPKeys.isDark, isDark);
}

bool getIsDark() {
return prefs.getBool(SPKeys.isDark) ?? false;
}
}
Loading