diff --git a/android/app/build.gradle b/android/app/build.gradle index f5bac85..263ec7e 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 33 + compileSdkVersion 34 sourceSets { main.java.srcDirs += 'src/main/kotlin' diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index ee958ca..6cb317b 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,45 +1,46 @@ + - - - + - - + android:name="io.flutter.embedding.android.NormalTheme" + android:resource="@style/NormalTheme" /> + android:name="io.flutter.embedding.android.SplashScreenDrawable" + android:resource="@drawable/launch_background" /> - - + + - + + + + + + diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index 3a1d81b..7e69aed 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.1-all.zip diff --git a/lib/home_screen.dart b/lib/home_screen.dart new file mode 100644 index 0000000..3db5741 --- /dev/null +++ b/lib/home_screen.dart @@ -0,0 +1,46 @@ +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'themes/theme_provider.dart'; +import 'themes/theme_data.dart'; // Import AppThemes +import 'settings_page.dart'; // Import SettingsPage + +class HomeScreen extends StatelessWidget { + @override + Widget build(BuildContext context) { + final themeProvider = Provider.of(context); + + return Scaffold( + appBar: AppBar( + title: Text('P2P Messaging - AOSSIE'), + actions: [ + IconButton( + icon: Icon(Icons.settings), + onPressed: () { + Navigator.push( + context, + MaterialPageRoute(builder: (context) => SettingsPage()), + ); + }, + ), + ], + ), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + 'Your app\'s main content goes here.', + style: TextStyle(fontSize: 18), + ), + SizedBox(height: 20), + SwitchListTile( + title: Text('Dark Mode'), + value: themeProvider.currentTheme == AppThemes.darkTheme, + onChanged: (_) => themeProvider.toggleTheme(), + ), + ], + ), + ), + ); + } +} diff --git a/lib/main.dart b/lib/main.dart index e81a183..4ac0fc4 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,52 +1,26 @@ -/// The logic for the Adhoc and the UI are separated. -/// The different section are listed as follows -/// - p2p => Backend of application where message protocols, connections, state are managed -/// - pages => This is the UI section of the application -/// - encryption => The messages are encrypted here. -/// - database => Storage for our messages and conversations -/// - classes => Different model classes for databases -/// - components => Common UI components - import 'package:flutter/material.dart'; -import 'classes/Global.dart'; import 'package:provider/provider.dart'; -import 'pages/Profile.dart'; +import 'themes/theme_provider.dart'; +import 'home_screen.dart'; void main() { runApp( - // Provider is used for state management. The state management will help us - // to know when a new message has arrived and to refresh the chat page. - MultiProvider( - providers: [ - ChangeNotifierProvider( - // Currently we have single class for to manage which contains the - // required data and streams - create: (_) => Global(), - ), - ], + ChangeNotifierProvider( + create: (_) => ThemeProvider(), // Provide ThemeProvider for theme management child: MyApp(), ), ); } -Route generateRoute(RouteSettings settings) { - // Initially app opens the profile page where we need to either create - // new profile or - // navigate to the home screen - return MaterialPageRoute( - builder: (_) => Profile( - onLogin: true, - ), - ); -} - class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { + final themeProvider = Provider.of(context); + return MaterialApp( debugShowCheckedModeBanner: false, - onGenerateRoute: generateRoute, - initialRoute: '/', + theme: themeProvider.currentTheme, // Dynamically set the theme + home: HomeScreen(), // Home screen of the app ); } } diff --git a/lib/settings_page.dart b/lib/settings_page.dart new file mode 100644 index 0000000..78fee2b --- /dev/null +++ b/lib/settings_page.dart @@ -0,0 +1,31 @@ +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'themes/theme_provider.dart'; +import 'themes/theme_data.dart'; // Import AppThemes + +class SettingsPage extends StatelessWidget { + @override + Widget build(BuildContext context) { + // Access the ThemeProvider to manage theme toggling + final themeProvider = Provider.of(context); + + return Scaffold( + appBar: AppBar( + title: Text("Settings"), // Title for the AppBar + ), + body: ListView( + children: [ + ListTile( + title: Text("Dark Mode"), + trailing: Switch( + value: themeProvider.currentTheme == AppThemes.darkTheme, + onChanged: (value) { + themeProvider.toggleTheme(); + }, + ), + ), + ], + ), + ); + } +} diff --git a/lib/themes/theme_data.dart b/lib/themes/theme_data.dart new file mode 100644 index 0000000..2ba4202 --- /dev/null +++ b/lib/themes/theme_data.dart @@ -0,0 +1,23 @@ +import 'package:flutter/material.dart'; + +class AppThemes { + static final ThemeData lightTheme = ThemeData( + brightness: Brightness.light, + primarySwatch: Colors.blue, + scaffoldBackgroundColor: Colors.white, + appBarTheme: AppBarTheme( + backgroundColor: Colors.blue, + foregroundColor: Colors.white, + ), + ); + + static final ThemeData darkTheme = ThemeData( + brightness: Brightness.dark, + primarySwatch: Colors.teal, + scaffoldBackgroundColor: Colors.black, + appBarTheme: AppBarTheme( + backgroundColor: Colors.teal, + foregroundColor: Colors.white, + ), + ); +} diff --git a/lib/themes/theme_provider.dart b/lib/themes/theme_provider.dart new file mode 100644 index 0000000..6ab4810 --- /dev/null +++ b/lib/themes/theme_provider.dart @@ -0,0 +1,30 @@ +import 'package:flutter/material.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import 'theme_data.dart'; + +class ThemeProvider extends ChangeNotifier { + ThemeData _currentTheme = AppThemes.lightTheme; + + ThemeProvider() { + _loadTheme(); + } + + ThemeData get currentTheme => _currentTheme; + + void toggleTheme() async { + _currentTheme = + _currentTheme == AppThemes.lightTheme ? AppThemes.darkTheme : AppThemes.lightTheme; + notifyListeners(); + + // Persist theme choice + SharedPreferences prefs = await SharedPreferences.getInstance(); + prefs.setBool('isDarkTheme', _currentTheme == AppThemes.darkTheme); + } + + void _loadTheme() async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + bool isDarkTheme = prefs.getBool('isDarkTheme') ?? false; + _currentTheme = isDarkTheme ? AppThemes.darkTheme : AppThemes.lightTheme; + notifyListeners(); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 065e636..3f00a36 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -21,12 +21,12 @@ dependencies: intl: ^0.17.0 rsa_encrypt: ^2.0.0 pointycastle: ^3.0.1 - shared_preferences: ^2.0.15 - provider: ^6.0.3 - + shared_preferences: ^2.0.15 # Required for saving theme preference + provider: ^6.0.3 # Required for state management (e.g., ThemeProvider) + dev_dependencies: flutter_test: sdk: flutter flutter: - uses-material-design: true \ No newline at end of file + uses-material-design: true