neckaros / secure_application

Secure your application from prying eyes
MIT License
103 stars 62 forks source link

SecureApplicationProvider.of(context) crashes #7

Open Kostya1375 opened 4 years ago

Kostya1375 commented 4 years ago

I've wrapped my app as guided in to SecureApplication

return MaterialApp(
        title: Strings.appName,
        theme: ThemeData(...),
        home: SecureApplication(
          child: SecureGate(
              lockedBuilder: (context, secureApplicationController) =>
                  AuthPage(secureApplicationController),
              child: RatesPage()),
        ),
        navigatorObservers: [
          FirebaseAnalyticsObserver(...)
        ]);

And now after multiple navigations to other pages I'm trying to get instance of SecureApplicaitonController to enable/disable securing

class SecurityPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _SecurityPageState();
}

class _SecurityPageState extends State<SecurityPage> {
  final LocalAuthentication _auth = LocalAuthentication();
  SecurityState _state = SecurityState(null, null);
  SharedPreferences _prefs;

  @override
  void initState() {
    super.initState();
    SharedPreferences.getInstance().then(onPreferencesAcquired);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(...),
      body: SecureGate(
        child: Builder(
          builder: (context) {
            var valueNotifier = SecureApplicationProvider.of(context); // <- Here comes the problems
            return Column(children: _getSettingsList(valueNotifier));
          },
        ),
      ),
    );
  }

And now I'm getting this error:

When the exception was thrown, this was the stack:
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1      SecureApplicationProvider.of (package:secure_application/secure_application_provider.dart:24:12)
#2      _SecureGateState.didChangeDependencies (package:secure_application/secure_gate.dart:60:64)
#3      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4705:12)
#4      ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
...     Normal element mounting (19 frames)
#23     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
#24     MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5991:32)
...     Normal element mounting (210 frames)
#234    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
#235    Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
#236    RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5624:32)
#237    MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6001:17)
#238    Element.updateChild (package:flutter/src/widgets/framework.dart:3245:15)
#239    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
#240    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4719:11)
#241    Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
#242    StatefulElement.update (package:flutter/src/widgets/framework.dart:4751:5)
#243    Element.updateChild (package:flutter/src/widgets/framework.dart:3245:15)
#244    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
#245    Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
#246    ProxyElement.update (package:flutter/src/widgets/framework.dart:4906:5)
#247    _InheritedNotifierElement.update (package:flutter/src/widgets/inherited_notifier.dart:183:11)
#248    Element.updateChild (package:flutter/src/widgets/framework.dart:3245:15)
#249    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5881:14)
#250    Element.updateChild (package:flutter/src/widgets/framework.dart:3245:15)
#251    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
#252    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4719:11)
#253    Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
#254    StatefulElement.update (package:flutter/src/widgets/framework.dart:4751:5)
#255    Element.updateChild (package:flutter/src/widgets/framework.dart:3245:15)
#256    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5881:14)
#257    Element.updateChild (package:flutter/src/widgets/framework.dart:3245:15)
#258    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5881:14)
#259    Element.updateChild (package:flutter/src/widgets/framework.dart:3245:15)
#260    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
#261    Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
#262    StatelessElement.update (package:flutter/src/widgets/framework.dart:4627:5)
#263    Element.updateChild (package:flutter/src/widgets/framework.dart:3245:15)
#264    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
#265    Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
#266    ProxyElement.update (package:flutter/src/widgets/framework.dart:4906:5)
#267    Element.updateChild (package:flutter/src/widgets/framework.dart:3245:15)
#268    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
#269    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4719:11)
#270    Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
#271    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2667:33)
#272    WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:866:20)
#273    RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:286:5)
#274    SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15)
#275    SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1056:9)
#276    SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:972:5)
#280    _invoke (dart:ui/hooks.dart:253:10)
#281    _drawFrame (dart:ui/hooks.dart:211:3)
(elided 3 frames from dart:async)

════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following NoSuchMethodError was thrown building _BodyBuilder:
The getter 'secureData' was called on null.
Receiver: null
Tried calling: secureData

The relevant error-causing widget was: 
  Scaffold file:///Users/kostya1375/FlutterProjects/GodexApp/lib/ui/screen/settings_screen.dart:255:12
When the exception was thrown, this was the stack: 
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1      SecureApplicationProvider.of (package:secure_application/secure_application_provider.dart:24:12)
#2      _SecureGateState.didChangeDependencies (package:secure_application/secure_gate.dart:60:64)
#3      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4705:12)
#4      ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
...
TreyThomas93 commented 2 years ago

Most likely the context you are passing is null.