Skip to content

Commit

Permalink
fix ui not loading
Browse files Browse the repository at this point in the history
  • Loading branch information
maheshj01 committed Jan 5, 2024
1 parent 40cf19a commit 2662f61
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 158 deletions.
171 changes: 88 additions & 83 deletions lib/base_home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class _AdaptiveLayoutState extends ConsumerState<AdaptiveLayout> {
}
try {
final appController = ref.read(appProvider);

final appUtility = ref.read(appUtilityProvider);
final packageInfo = await PackageInfo.fromPlatform();
final String appVersion = packageInfo.version;
final int appBuildNumber = int.parse(packageInfo.buildNumber);
Expand All @@ -84,9 +84,9 @@ class _AdaptiveLayoutState extends ConsumerState<AdaptiveLayout> {
await remoteConfig.fetchAndActivate();
final version = remoteConfig.getString('${Constants.VERSION_KEY}');
final buildNumber = remoteConfig.getInt('${Constants.BUILD_NUMBER_KEY}');

final oldVersion = appController.version.split(' ')[0];
final oldBuildNumber = int.parse(appController.version.split(' ')[1]);
final storedVersion = appUtility.getVersion();
final oldVersion = storedVersion.split(' ')[0];
final oldBuildNumber = int.parse(storedVersion.split(' ')[1]);
if (appVersion != version || buildNumber > appBuildNumber) {
ref
.read(appProvider.notifier)
Expand All @@ -99,14 +99,15 @@ class _AdaptiveLayoutState extends ConsumerState<AdaptiveLayout> {
if (oldVersion != version || oldBuildNumber < buildNumber) {
Navigate.push(
context,
WhatsNew(),
WhatsNew(
showFullChangelog: false,
),
transitionType: TransitionType.btt,
);
ref.read(appProvider.notifier).copyWith(appController.copyWith(
showFAB: true,
extended: true,
hasUpdate: false,
version: '$appVersion $appBuildNumber'));

appUtility.setAppVersion(
'$version $buildNumber',
);
}
}
} catch (_) {
Expand Down Expand Up @@ -231,85 +232,89 @@ class _AdaptiveLayoutState extends ConsumerState<AdaptiveLayout> {
}
}

return Scaffold(
resizeToAvoidBottomInset: false,
floatingActionButton: appController.hasUpdate ? null : _buildFab(),
body: Stack(
children: [
NavbarRouter(
errorBuilder: (context) {
return const Center(child: Text('Error 404'));
},
type: NavbarType.floating,
onBackButtonPressed: (isExiting) {
if (isExiting) {
newTime = DateTime.now();
final int difference = newTime.difference(oldTime).inMilliseconds;
oldTime = newTime;
if (difference < 1000) {
hideToast();
return isExiting;
} else {
showToast('Press again to exit');
return false;
}
} else {
return isExiting;
}
},
shouldPopToBaseRoute: true,
isDesktop: !SizeUtils.isMobile,
// destinationAnimationCurve: Curves.fastOutSlowIn,
destinationAnimationDuration: SizeUtils.isDesktop ? 0 : 0,
onCurrentTabClicked: () {
exploreController.scrollToIndex = 0;
},
onChanged: (x) async {
ref.read(appProvider.notifier).copyWith(appController.copyWith(
index: x, showFAB: x < 2 && user!.isLoggedIn, extended: true));
return AnimatedBuilder(
animation: dashboardController,
builder: (context, child) {
return Scaffold(
resizeToAvoidBottomInset: false,
floatingActionButton: appController.hasUpdate ? null : _buildFab(),
body: Stack(
children: [
NavbarRouter(
errorBuilder: (context) {
return const Center(child: Text('Error 404'));
},
type: NavbarType.floating,
onBackButtonPressed: (isExiting) {
if (isExiting) {
newTime = DateTime.now();
final int difference = newTime.difference(oldTime).inMilliseconds;
oldTime = newTime;
if (difference < 1000) {
hideToast();
return isExiting;
} else {
showToast('Press again to exit');
return false;
}
} else {
return isExiting;
}
},
shouldPopToBaseRoute: true,
isDesktop: !SizeUtils.isMobile,
// destinationAnimationCurve: Curves.fastOutSlowIn,
destinationAnimationDuration: SizeUtils.isDesktop ? 0 : 0,
onCurrentTabClicked: () {
exploreController.scrollToIndex = 0;
},
onChanged: (x) async {
ref.read(appProvider.notifier).copyWith(appController.copyWith(
index: x, showFAB: x < 2 && user!.isLoggedIn, extended: true));

/// Simulate DragGesture on pageView
final pageController = exploreController.pageController;
if (EXPLORE_INDEX == x && SizeUtils.isMobile) {
if (pageController.hasClients) {
if (exploreController.shouldShowScrollAnimation) {
Future.delayed(Duration(seconds: 3), () async {
if (NavbarNotifier.currentIndex == EXPLORE_INDEX) {
exploreController.showScrollAnimation();
/// Simulate DragGesture on pageView
final pageController = exploreController.pageController;
if (EXPLORE_INDEX == x && SizeUtils.isMobile) {
if (pageController.hasClients) {
if (exploreController.shouldShowScrollAnimation) {
Future.delayed(Duration(seconds: 3), () async {
if (NavbarNotifier.currentIndex == EXPLORE_INDEX) {
exploreController.showScrollAnimation();
}
});
}
}
});
}
}
}
},
decoration: FloatingNavbarDecoration(
height: kNavbarHeight * 1.2,
backgroundColor: SizeUtils.isDesktop
? colorScheme.surfaceVariant
: colorScheme.scrim.withOpacity(0.2),
margin: EdgeInsets.zero,
showSelectedLabels: false,
borderRadius: BorderRadius.zero,
// backgroundColor: (colorScheme.surfaceVariant.withOpacity(0.4)),
),
destinations: [
for (int i = 0; i < items.length; i++)
DestinationRouter(
navbarItem: items[i],
}
},
decoration: FloatingNavbarDecoration(
height: kNavbarHeight * 1.2,
backgroundColor: SizeUtils.isDesktop
? colorScheme.surfaceVariant
: colorScheme.scrim.withOpacity(0.2),
margin: EdgeInsets.zero,
showSelectedLabels: false,
borderRadius: BorderRadius.zero,
// backgroundColor: (colorScheme.surfaceVariant.withOpacity(0.4)),
),
destinations: [
for (int j = 0; j < _routes[i]!.keys.length; j++)
Destination(
route: _routes[i]!.keys.elementAt(j),
widget: _routes[i]!.values.elementAt(j),
for (int i = 0; i < items.length; i++)
DestinationRouter(
navbarItem: items[i],
destinations: [
for (int j = 0; j < _routes[i]!.keys.length; j++)
Destination(
route: _routes[i]!.keys.elementAt(j),
widget: _routes[i]!.values.elementAt(j),
),
],
initialRoute: _routes[i]!.keys.elementAt(0),
),
],
initialRoute: _routes[i]!.keys.elementAt(0),
),
],
),
],
),
);
],
),
);
});
}
}

Expand Down
89 changes: 55 additions & 34 deletions lib/controller/app_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:vocabhub/services/services.dart';

@immutable
class AppController {
Expand All @@ -10,29 +11,30 @@ class AppController {
final bool extended;
final bool hasUpdate;
final String version;

AppController({
this.index = 0,
this.showFAB = true,
this.extended = true,
this.hasUpdate = false,
this.version = '1.0.0 1',
});

AppController copyWith({
int? index,
bool? showFAB,
bool? extended,
bool? hasUpdate,
String? version,
}) {
final String oldVersion;

AppController(
{this.index = 0,
this.showFAB = true,
this.extended = true,
this.hasUpdate = false,
this.version = '1.0.0 1',
this.oldVersion = '1.0.0 1'});

AppController copyWith(
{int? index,
bool? showFAB,
bool? extended,
bool? hasUpdate,
String? version,
String? oldVersion}) {
return AppController(
index: index ?? this.index,
showFAB: showFAB ?? this.showFAB,
extended: extended ?? this.extended,
hasUpdate: hasUpdate ?? this.hasUpdate,
version: version ?? this.version,
);
index: index ?? this.index,
showFAB: showFAB ?? this.showFAB,
extended: extended ?? this.extended,
hasUpdate: hasUpdate ?? this.hasUpdate,
version: version ?? this.version,
oldVersion: oldVersion ?? this.oldVersion);
}

Map<String, dynamic> toMap() {
Expand All @@ -43,17 +45,18 @@ class AppController {
result.addAll({'extended': extended});
result.addAll({'hasUpdate': hasUpdate});
result.addAll({'version': version});
result.addAll({'oldVersion': oldVersion});
return result;
}

factory AppController.fromMap(Map<String, dynamic> map) {
return AppController(
index: map['index']?.toInt() ?? 0,
showFAB: map['showFAB'] ?? false,
extended: map['extended'] ?? false,
hasUpdate: map['hasUpdate'] ?? false,
version: map['version'] ?? '1.0.0 1',
);
index: map['index']?.toInt() ?? 0,
showFAB: map['showFAB'] ?? false,
extended: map['extended'] ?? false,
hasUpdate: map['hasUpdate'] ?? false,
version: map['version'] ?? '1.0.0 1',
oldVersion: map['oldVersion'] ?? '1.0.0 1');
}

String toJson() => json.encode(toMap());
Expand All @@ -62,7 +65,7 @@ class AppController {

@override
String toString() {
return 'AppController(index: $index, showFAB: $showFAB, extended: $extended, hasUpdate: $hasUpdate, version: $version)';
return 'AppController(index: $index, showFAB: $showFAB, extended: $extended, hasUpdate: $hasUpdate, version: $version oldVersion: $oldVersion)';
}

@override
Expand All @@ -74,7 +77,8 @@ class AppController {
other.showFAB == showFAB &&
other.extended == extended &&
other.hasUpdate == hasUpdate &&
other.version == version;
other.version == version &&
other.oldVersion == oldVersion;
}

@override
Expand All @@ -83,13 +87,24 @@ class AppController {
showFAB.hashCode ^
extended.hashCode ^
hasUpdate.hashCode ^
version.hashCode;
version.hashCode ^
oldVersion.hashCode;
}
}

class AppNotifier extends StateNotifier<AppController> {
AppNotifier(super.state);

AppNotifier(this.ref)
: super(AppController(
extended: true,
index: 0,
showFAB: true,
hasUpdate: false,
oldVersion: "1.0.0 1",
version: "1.0.0 1")) {
final oldVer = ref.read(appUtilityProvider).getVersion();
state.copyWith(oldVersion: oldVer);
}
Ref ref;
void setIndex(int index) {
state = state.copyWith(index: index);
}
Expand All @@ -110,12 +125,18 @@ class AppNotifier extends StateNotifier<AppController> {
state = state.copyWith(version: version);
}

void setOldVersion(String oldVersion) {
state = state.copyWith(oldVersion: oldVersion);
ref.read(appUtilityProvider).setAppVersion(oldVersion);
}

void copyWith(AppController appController) {
state = state.copyWith(
index: appController.index,
showFAB: appController.showFAB,
extended: appController.extended,
hasUpdate: appController.hasUpdate,
version: appController.version);
version: appController.version,
oldVersion: appController.oldVersion);
}
}
11 changes: 11 additions & 0 deletions lib/controller/dashboard_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import 'package:vocabhub/services/services.dart';
import 'package:vocabhub/services/services/service_base.dart';

class DashboardController extends ChangeNotifier with ServiceBase {
bool _isLoading = true;

bool get isLoading => _isLoading;

set isLoading(bool isLoading) {
_isLoading = isLoading;
notifyListeners();
}

Word? _wordOfTheDay;
late final DashboardService _dashboardService;
final List<Word> _words = [];
Expand Down Expand Up @@ -46,13 +55,15 @@ class DashboardController extends ChangeNotifier with ServiceBase {
@override
Future<void> initService() async {
try {
isLoading = true;
if (_wordOfTheDay == null) {
_wordOfTheDay = Word.init();
}
_dashboardService = DashboardService();
await _dashboardService.initService();
_wordOfTheDay = await getLastPublishedWord();
words = await _dashboardService.getWords();
isLoading = false;
} catch (e) {
rethrow;
}
Expand Down
Loading

0 comments on commit 2662f61

Please sign in to comment.