Skip to content

Commit

Permalink
Revert "fix flash of login screen when uploading"
Browse files Browse the repository at this point in the history
This reverts commit 5db9224 for #14
  • Loading branch information
qcasey committed Jan 16, 2022
1 parent d791897 commit b600c2c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 43 deletions.
81 changes: 41 additions & 40 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@ import 'share.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

final AuthModel _auth = AuthModel();

void main() async {
WidgetsFlutterBinding.ensureInitialized();
try {
await _auth.loadSettings();
} catch (e) {
print("Error Loading Settings: $e");
}
void main() {
runApp(PaperlessShare());
}

Expand Down Expand Up @@ -45,8 +37,15 @@ MaterialColor createMaterialColor(Color color) {
}

class _PaperlessShareState extends State<PaperlessShare> {
final AuthModel _auth = AuthModel();

@override
void initState() {
try {
_auth.loadSettings();
} catch (e) {
print("Error Loading Settings: $e");
}
super.initState();
}

Expand All @@ -56,36 +55,38 @@ class _PaperlessShareState extends State<PaperlessShare> {
providers: [
ChangeNotifierProvider<AuthModel>.value(value: _auth),
],
child: Consumer<AuthModel>(builder: (context, model, child) {
return MaterialApp(
title: 'Paperless Share',
theme: ThemeData(
primarySwatch: createMaterialColor(Color(0xFF17541f)),
brightness: Brightness.light,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
darkTheme: ThemeData(
primarySwatch: createMaterialColor(Color(0xFF17541f)),
accentColor: Colors.green,
brightness: Brightness.dark,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
initialRoute: model?.user.isValid() ? '/share' : '/login',
routes: {
'/login': (context) => new LoginPage(),
'/share': (context) => new SharePage(),
},
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [
const Locale('en', ''),
const Locale('de', ''),
],
);
}));
child: MaterialApp(
title: 'Paperless Share',
theme: ThemeData(
primarySwatch: createMaterialColor(Color(0xFF17541f)),
brightness: Brightness.light,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
darkTheme: ThemeData(
primarySwatch: createMaterialColor(Color(0xFF17541f)),
accentColor: Colors.green,
brightness: Brightness.dark,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: Consumer<AuthModel>(builder: (context, model, child) {
if (model?.user != null && model?.user.isValid())
return SharePage();
return LoginPage();
}),
routes: {
'/login': (context) => new LoginPage(),
'/share': (context) => new SharePage(),
},
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [
const Locale('en', ''),
const Locale('de', ''),
],
));
}
}
4 changes: 1 addition & 3 deletions lib/model/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AuthModel extends ChangeNotifier {
String errorMessage = "";
User _user;

Future<bool> loadSettings() async {
void loadSettings() async {
var _prefs = EncryptedSharedPreferences();

User _savedUser;
Expand All @@ -50,12 +50,10 @@ class AuthModel extends ChangeNotifier {
token: await _prefs.getString("saved_token"));
} catch (e) {
print("User Not Found: $e");
return false;
}
_user = _savedUser;

notifyListeners();
return true;
}

User get user => _user;
Expand Down

0 comments on commit b600c2c

Please sign in to comment.