fixed linting warning to main.dart
This commit is contained in:
parent
e388a7140e
commit
dfd8b97f26
1 changed files with 29 additions and 20 deletions
|
@ -28,7 +28,7 @@ final BehaviorSubject<String?> selectNotificationSubject = BehaviorSubject<Strin
|
||||||
String? selectedNotificationPayload;
|
String? selectedNotificationPayload;
|
||||||
|
|
||||||
|
|
||||||
void main() async {
|
Future<void> main() async {
|
||||||
// hive init
|
// hive init
|
||||||
await Hive.initFlutter();
|
await Hive.initFlutter();
|
||||||
|
|
||||||
|
@ -39,18 +39,17 @@ void main() async {
|
||||||
Hive.registerAdapter(IngredientAdapter());
|
Hive.registerAdapter(IngredientAdapter());
|
||||||
|
|
||||||
await Hive.openBox<PizzaEvent>("PizzaEvents");
|
await Hive.openBox<PizzaEvent>("PizzaEvents");
|
||||||
var pizzaRecipesBox = await Hive.openBox<PizzaRecipe>("PizzaRecipes");
|
final pizzaRecipesBox = await Hive.openBox<PizzaRecipe>("PizzaRecipes");
|
||||||
|
|
||||||
if (pizzaRecipesBox.isEmpty){
|
if (pizzaRecipesBox.isEmpty){
|
||||||
print("Load pizzas from yamls");
|
|
||||||
pizzaRecipesBox.addAll(await getRecipes());
|
pizzaRecipesBox.addAll(await getRecipes());
|
||||||
}
|
}
|
||||||
|
|
||||||
// notification init
|
// notification init
|
||||||
const initializationSettingsAndroid = AndroidInitializationSettings('@mipmap/app_icon');
|
const initializationSettingsAndroid = AndroidInitializationSettings('@mipmap/app_icon');
|
||||||
final initializationSettingsIOS = IOSInitializationSettings();
|
const initializationSettingsIOS = IOSInitializationSettings();
|
||||||
final initializationSettingsMacOS = MacOSInitializationSettings();
|
const initializationSettingsMacOS = MacOSInitializationSettings();
|
||||||
final initializationSettings = InitializationSettings(
|
const initializationSettings = InitializationSettings(
|
||||||
android: initializationSettingsAndroid,
|
android: initializationSettingsAndroid,
|
||||||
iOS: initializationSettingsIOS,
|
iOS: initializationSettingsIOS,
|
||||||
macOS: initializationSettingsMacOS
|
macOS: initializationSettingsMacOS
|
||||||
|
@ -59,20 +58,18 @@ void main() async {
|
||||||
initializationSettings,
|
initializationSettings,
|
||||||
onSelectNotification: (String? payload) async {
|
onSelectNotification: (String? payload) async {
|
||||||
selectedNotificationPayload = payload;
|
selectedNotificationPayload = payload;
|
||||||
print("onSelectNotification");
|
|
||||||
selectNotificationSubject.add(payload);
|
selectNotificationSubject.add(payload);
|
||||||
});
|
});
|
||||||
|
|
||||||
// init timezones properly
|
// init timezones properly
|
||||||
tz.initializeTimeZones();
|
tz.initializeTimeZones();
|
||||||
final String? timeZoneName = await FlutterNativeTimezone.getLocalTimezone();
|
final String timeZoneName = await FlutterNativeTimezone.getLocalTimezone();
|
||||||
tz.setLocalLocation(tz.getLocation(timeZoneName!));
|
tz.setLocalLocation(tz.getLocation(timeZoneName));
|
||||||
|
|
||||||
final NotificationAppLaunchDetails? notificationAppLaunchDetails = await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails();
|
final NotificationAppLaunchDetails? notificationAppLaunchDetails = await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails();
|
||||||
String initialRoute = "/";
|
String initialRoute = "/";
|
||||||
if (notificationAppLaunchDetails?.didNotificationLaunchApp ?? false) {
|
if (notificationAppLaunchDetails?.didNotificationLaunchApp ?? false) {
|
||||||
selectedNotificationPayload = notificationAppLaunchDetails!.payload;
|
selectedNotificationPayload = notificationAppLaunchDetails!.payload;
|
||||||
print("Started by notification");
|
|
||||||
initialRoute = "/event/notification";
|
initialRoute = "/event/notification";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +81,7 @@ void main() async {
|
||||||
class PizzaPlanner extends StatefulWidget {
|
class PizzaPlanner extends StatefulWidget {
|
||||||
final String initialRoute;
|
final String initialRoute;
|
||||||
|
|
||||||
PizzaPlanner(this.initialRoute);
|
const PizzaPlanner(this.initialRoute);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
PizzaPlannerState createState() => PizzaPlannerState();
|
PizzaPlannerState createState() => PizzaPlannerState();
|
||||||
|
@ -94,28 +91,27 @@ class PizzaPlannerState extends State<PizzaPlanner> {
|
||||||
// need this because in _configureSelectNotificationSubject() we need to pushNamed a route
|
// need this because in _configureSelectNotificationSubject() we need to pushNamed a route
|
||||||
// but only descendants of a MaterialApp have access to the Navigator,
|
// but only descendants of a MaterialApp have access to the Navigator,
|
||||||
// and this build() returns the MaterialApp
|
// and this build() returns the MaterialApp
|
||||||
final GlobalKey<NavigatorState> navigatorKey = new GlobalKey<NavigatorState>();
|
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState(){
|
void initState(){
|
||||||
super.initState();
|
super.initState();
|
||||||
this._configureSelectNotificationSubject();
|
_configureSelectNotificationSubject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: "PizzaPlanner",
|
title: "PizzaPlanner",
|
||||||
initialRoute: this.widget.initialRoute,
|
initialRoute: widget.initialRoute,
|
||||||
navigatorKey: this.navigatorKey,
|
navigatorKey: navigatorKey,
|
||||||
onGenerateRoute: RouteGenerator.generateRoute,
|
onGenerateRoute: RouteGenerator.generateRoute,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _configureSelectNotificationSubject() {
|
void _configureSelectNotificationSubject() {
|
||||||
selectNotificationSubject.stream.listen((String? payload) async {
|
selectNotificationSubject.stream.listen((String? payload) async {
|
||||||
print("tapped on notification");
|
await navigatorKey.currentState?.pushNamed('/event/notification', arguments: payload);
|
||||||
await this.navigatorKey.currentState?.pushNamed('/event/notification', arguments: payload);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,13 +126,25 @@ class RouteGenerator {
|
||||||
return MaterialPageRoute(builder: (context) => PickPizzaRecipePage());
|
return MaterialPageRoute(builder: (context) => PickPizzaRecipePage());
|
||||||
}
|
}
|
||||||
case "/event/add": {
|
case "/event/add": {
|
||||||
return MaterialPageRoute(builder: (context) => AddPizzaEventPage(settings.arguments as PizzaRecipe));
|
final pizzaRecipe = settings.arguments as PizzaRecipe?;
|
||||||
|
if (pizzaRecipe == null){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return MaterialPageRoute(builder: (context) => AddPizzaEventPage(pizzaRecipe));
|
||||||
}
|
}
|
||||||
case "/event/view": {
|
case "/event/view": {
|
||||||
return MaterialPageRoute(builder: (context) => PizzaEventPage(settings.arguments as PizzaEvent));
|
final pizzaEvent = settings.arguments as PizzaEvent?;
|
||||||
|
if (pizzaEvent == null){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return MaterialPageRoute(builder: (context) => PizzaEventPage(pizzaEvent));
|
||||||
}
|
}
|
||||||
case "/event/recipe": {
|
case "/event/recipe": {
|
||||||
return MaterialPageRoute(builder: (context) => PizzaEventRecipePage(settings.arguments as PizzaEvent));
|
final pizzaEvent = settings.arguments as PizzaEvent?;
|
||||||
|
if (pizzaEvent == null){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return MaterialPageRoute(builder: (context) => PizzaEventRecipePage(pizzaEvent));
|
||||||
}
|
}
|
||||||
case "/event/notification": {
|
case "/event/notification": {
|
||||||
if (selectedNotificationPayload != null) {
|
if (selectedNotificationPayload != null) {
|
||||||
|
@ -154,6 +162,7 @@ class RouteGenerator {
|
||||||
return MaterialPageRoute(builder: (context) => PizzaEventsPage());
|
return MaterialPageRoute(builder: (context) => PizzaEventsPage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return MaterialPageRoute(builder: (context) => PizzaEventsPage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue