Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Merged in bugfix/HP-66-event-screen (pull request #42)
Browse files Browse the repository at this point in the history
Bugfix/HP-66 event screen

Approved-by: Anton Utz
  • Loading branch information
Tom Freudenmann authored and ant-u committed May 12, 2022
2 parents c6fb38e + 8ead0c7 commit 1b511c9
Show file tree
Hide file tree
Showing 66 changed files with 2,212 additions and 1,919 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@ lib/generated_plugin_registrant.dart
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages

gradle.properties
.vscode/launch.json
2 changes: 1 addition & 1 deletion lib/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ bool modeInit = false;
UtilService utilServiceConfig = UtilService();

int notificationNextId = 0;
NotificationService notificationService = NotificationService();
NotificationService notificationService = NotificationService();
83 changes: 38 additions & 45 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,21 @@ import 'screens/notifications/notification.dart';
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();

// Settings for the notification class
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();

/// Streams are created so that app can respond to notification-related events
/// since the plugin is initialised in the `main` function
final BehaviorSubject<ReceivedNotification> didReceiveLocalNotificationSubject = BehaviorSubject<ReceivedNotification>();
final BehaviorSubject<String?> selectNotificationSubject = BehaviorSubject<String?>();
final BehaviorSubject<ReceivedNotification> didReceiveLocalNotificationSubject =
BehaviorSubject<ReceivedNotification>();
final BehaviorSubject<String?> selectNotificationSubject =
BehaviorSubject<String?>();
String? selectedNotificationPayload;



/// Start the app
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();



/// INIT SHARED PREFS
sharedPreferences = await SharedPreferences.getInstance();

Expand All @@ -51,35 +50,33 @@ Future<void> main() async {
/// INIT NOTIFICATIONS
await _configureLocalTimeZone();

final NotificationAppLaunchDetails? notificationAppLaunchDetails = !kIsWeb && Platform.isLinux
? null : await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails();
final NotificationAppLaunchDetails? notificationAppLaunchDetails = !kIsWeb &&
Platform.isLinux
? null
: await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails();

const AndroidInitializationSettings initializationSettingsAndroid = AndroidInitializationSettings('ic_launcher');
const AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings('ic_launcher');

const InitializationSettings initializationSettings = InitializationSettings(android: initializationSettingsAndroid);
const InitializationSettings initializationSettings =
InitializationSettings(android: initializationSettingsAndroid);

await flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: (String? payload) async {
if (payload != null) {
debugPrint('notification payload: $payload');
}
selectedNotificationPayload = payload;
selectNotificationSubject.add(payload);
}
);


if (payload != null) {
debugPrint('notification payload: $payload');
}
selectedNotificationPayload = payload;
selectNotificationSubject.add(payload);
});

/// LOAD FIREBASE
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);


/// START APP
runApp(
MyApp(notificationAppLaunchDetails: notificationAppLaunchDetails)
);
runApp(MyApp(notificationAppLaunchDetails: notificationAppLaunchDetails));
}

/// Configures the local time Zone for the project
Expand All @@ -96,17 +93,16 @@ Future<void> _configureLocalTimeZone() async {
class MyApp extends StatefulWidget {
const MyApp({Key? key, this.notificationAppLaunchDetails}) : super(key: key);


final NotificationAppLaunchDetails? notificationAppLaunchDetails;

bool get didNotificationLaunchApp => notificationAppLaunchDetails?.didNotificationLaunchApp ?? false;
bool get didNotificationLaunchApp =>
notificationAppLaunchDetails?.didNotificationLaunchApp ?? false;

@override
State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

@override
void initState() {
super.initState();
Expand All @@ -117,27 +113,26 @@ class _MyAppState extends State<MyApp> {
// NotificationScreen stuff
_requestPermissions();
_configureDidReceiveLocalNotificationSubject();

}

/// Request notification permissions
void _requestPermissions() {
flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
IOSFlutterLocalNotificationsPlugin>()
IOSFlutterLocalNotificationsPlugin>()
?.requestPermissions(
alert: true,
badge: true,
sound: true,
);
alert: true,
badge: true,
sound: true,
);
flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
MacOSFlutterLocalNotificationsPlugin>()
MacOSFlutterLocalNotificationsPlugin>()
?.requestPermissions(
alert: true,
badge: true,
sound: true,
);
alert: true,
badge: true,
sound: true,
);
}

/// Checks if the notification arrives and gives it to the notification widget
Expand All @@ -161,8 +156,8 @@ class _MyAppState extends State<MyApp> {
await Navigator.push(
context,
MaterialPageRoute<void>(
builder: (BuildContext context) =>
NotificationScreen(eventId: receivedNotification.payload),
builder: (BuildContext context) => NotificationScreen(
eventId: receivedNotification.payload),
),
);
},
Expand All @@ -181,10 +176,8 @@ class _MyAppState extends State<MyApp> {
super.dispose();
}


@override
Widget build(BuildContext context) {

return StreamProvider<CustomUser?>.value(
value: AuthService().user,
initialData: null,
Expand All @@ -197,7 +190,9 @@ class _MyAppState extends State<MyApp> {
initialRoute: '/',
routes: {
'/': (_) => const Wrapper(),
NotificationScreen.routeName: (context) => NotificationScreen(eventId: selectedNotificationPayload,),
NotificationScreen.routeName: (context) => NotificationScreen(
eventId: selectedNotificationPayload,
),
'/newGarden': (context) => const NewGarden(),
'/forgetPassword': (context) => const ForgetPassword(),
'/signUp': (context) => const SignUpForm(),
Expand All @@ -206,5 +201,3 @@ class _MyAppState extends State<MyApp> {
);
}
}


11 changes: 6 additions & 5 deletions lib/screens/home/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'tabs/garden.dart';
import 'tabs/timeline.dart';
import 'tabs/options/options.dart';

class Home extends StatefulWidget{
class Home extends StatefulWidget {
const Home({Key? key, required this.title}) : super(key: key);
final String title;

Expand All @@ -29,10 +29,11 @@ class _HomeState extends State<Home> {
final dbUser = Provider.of<DbUser?>(context);

// Reloads until the db user is loaded
if(!modeInit) {
Future.delayed(Duration.zero,() {
if(dbUser != null && dbUser.settings != null){
currentTheme.changeThemeMode(dbUser.settings!.designSettings.colorScheme!);
if (!modeInit) {
Future.delayed(Duration.zero, () {
if (dbUser != null && dbUser.settings != null) {
currentTheme
.changeThemeMode(dbUser.settings!.designSettings.colorScheme!);
modeInit = true;
}
});
Expand Down
13 changes: 4 additions & 9 deletions lib/screens/home/tabs/garden.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class Garden extends StatefulWidget {
}

class _GardenState extends State<Garden> {


@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -24,19 +22,16 @@ class _GardenState extends State<Garden> {
floatingActionButton: FloatingActionButton(
onPressed: () {
// Navigate to new garden form
Navigator.pushNamed(
context,
'/newGarden'
);
Navigator.pushNamed(context, '/newGarden');
},
backgroundColor: Theme.of(context).primaryColor,

child: Icon(
Icons.add,
size: 35,
color: Theme.of(context).unselectedWidgetColor, //scaffoldBackgroundColor for turned around color
color: Theme.of(context)
.unselectedWidgetColor, //scaffoldBackgroundColor for turned around color
),
),
);
}
}
}
Loading

0 comments on commit 1b511c9

Please sign in to comment.