createApp method

Future<List<NewAppTask>> createApp()

Implementation

Future<List<NewAppTask>> createApp() async {
  List<NewAppTask> tasks = [];

  PublicMediumModel? logo;
  tasks.add(() async {
    print("Logo");
    try {
      logo = await RandomLogo.getRandomPhoto(app, memberId, null);
    } catch (_) {}
  });

  PublicMediumModel? anonymousMedium;
  tasks.add(() async {
    print("Anonymous photo");
    try {
      anonymousMedium = await PublicMediumAccessRights()
          .getMediumHelper(
            app,
            memberId,
          )
          .createThumbnailUploadPhotoAsset(newRandomKey(),
              'packages/eliud_pkg_create/assets/rodentia-icons_preferences-desktop-personal.png');
    } catch (_) {}
  });

  tasks.add(() async {
    print("leftDrawer");
    leftDrawer = await LeftDrawerBuilder(app, logo: logo).getOrCreate();
  });

  tasks.add(() async {
    print("rightDrawer");
    rightDrawer = await RightDrawerBuilder(
      app,
    ).getOrCreate();
  });

  tasks.add(() async {
    print("HomeMenu");
    theHomeMenu = await HomeMenuBuilder(
      app,
    ).getOrCreate();
  });

  tasks.add(() async {
    print("AppBar");
    theAppBar = await AppBarBuilder(
      app,
    ).getOrCreate();
  });

  tasks.add(() async {
    print("Welcome Page");
    if ((theHomeMenu != null) &&
        (theAppBar != null) &&
        (leftDrawer != null) &&
        (rightDrawer != null)) {
      await HelloWorldPageBuilder(
        uniqueId,
        helloWorldPageId,
        app,
        memberId,
        theHomeMenu!,
        theAppBar!,
        leftDrawer!,
        rightDrawer!,
      ).create();
    }
  });

  // app
  tasks.add(() async {
    print("App");
    var newApp = AppModel(
      documentID: appId,
      title: 'New application',
      ownerID: memberId,
      appStatus: AppStatus.live,
      email: member.email,
      logo: logo,
      anonymousProfilePhoto: anonymousMedium,
      homePages: AppHomePageReferencesModel(
        homePageBlockedMember: constructDocumentId(
            uniqueId: uniqueId, documentId: helloWorldPageId),
        homePagePublic: constructDocumentId(
            uniqueId: uniqueId, documentId: helloWorldPageId),
        homePageSubscribedMember: constructDocumentId(
            uniqueId: uniqueId, documentId: helloWorldPageId),
        homePageLevel1Member: constructDocumentId(
            uniqueId: uniqueId, documentId: helloWorldPageId),
        homePageLevel2Member: constructDocumentId(
            uniqueId: uniqueId, documentId: helloWorldPageId),
        homePageOwner: constructDocumentId(
            uniqueId: uniqueId, documentId: helloWorldPageId),
      ),
      description: 'Your new application',
    );
    /*newlyCreatedApp = */ await appRepository()!.update(newApp);
  });

  return tasks;
}