Skip to content

Method 'PopScope' isn't defined in 'RequestCode' class (resolution: use Flutter >3.16.0 or aad_oauth <=1.0.0)  #299

@tratum

Description

@tratum

When running the provided code, an error occurs related to the 'PopScope' method not being defined for the class 'RequestCode'. This error is observed in the request_code.dart file from the aad_oauth package.

Error:

Error: The method 'PopScope' isn't defined for the class 'RequestCode'.
 - 'RequestCode' is from 'package:aad_oauth/request_code.dart' ('/C:/Users/Saksham/AppData/Local/Pub/Cache/hosted/pub.dev/aad_oauth-1.0.1/lib/request_code.dart').
Try correcting the name to the name of an existing method, or defining a method named 'PopScope'.
          body: PopScope(
                ^^^^^^^^
Target kernel_snapshot failed: Exception


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'D:\Software\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 15s
Exception: Gradle task assembleDebug failed with exit code 1

Code Snippet

import 'package:aad_oauth/aad_oauth.dart';
import 'package:aad_oauth/model/config.dart';
import 'package:academeet/config/conf.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

final navigatorKey = GlobalKey<NavigatorState>();

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'AAD OAuth Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'AAD OAuth Home'),
      navigatorKey: navigatorKey,
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  static final Config config = Config(
    tenant: Conf.tenant,
    clientId: Conf.client_id,
    responseType: Conf.response_type,
    scope: Conf.scope,
    navigatorKey: navigatorKey,
    redirectUri: Conf.redirect_uri,
    loader: const Center(child: CircularProgressIndicator()),
    appBar: AppBar(
      title: const Text('AAD OAuth Demo'),
    ),
    onPageFinished: (String url) {
      if (kDebugMode) {
        print('onPageFinished: $url');
      }
    },
  );
  final AadOAuth oauth = AadOAuth(config);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: ListView(
        children: <Widget>[
          ListTile(
            title: Text(
              'AzureAD OAuth',
              style: Theme.of(context).textTheme.headlineSmall,
            ),
          ),
          ListTile(
            leading: const Icon(Icons.launch),
            title: const Text('Login${kIsWeb ? ' (web popup)' : ''}'),
            onTap: () {
              login(false);
            },
          ),
          if (kIsWeb)
            ListTile(
              leading: const Icon(Icons.launch),
              title: const Text('Login (web redirect)'),
              onTap: () {
                login(true);
              },
            ),
          ListTile(
            leading: const Icon(Icons.data_array),
            title: const Text('HasCachedAccountInformation'),
            onTap: () => hasCachedAccountInformation(),
          ),
          ListTile(
            leading: const Icon(Icons.logout),
            title: const Text('Logout'),
            onTap: () {
              logout();
            },
          ),
        ],
      ),
    );
  }

  void showError(dynamic ex) {
    showMessage(ex.toString());
  }

  void showMessage(String text) {
    var alert = AlertDialog(content: Text(text), actions: <Widget>[
      TextButton(
          child: const Text('Ok'),
          onPressed: () {
            Navigator.pop(context);
          })
    ]);
    showDialog(context: context, builder: (BuildContext context) => alert);
  }

  void login(bool redirect) async {
    config.webUseRedirect = redirect;
    final result = await oauth.login();
    result.fold(
          (l) => showError(l.toString()),
          (r) => showMessage('Logged in successfully, your access token: $r'),
    );
    var accessToken = await oauth.getAccessToken();
    if (accessToken != null) {
      if(context.mounted){
        ScaffoldMessenger.of(context).hideCurrentSnackBar();
        ScaffoldMessenger.of(context)
            .showSnackBar(SnackBar(content: Text(accessToken)));
      }
    }
  }

  void hasCachedAccountInformation() async {
    var hasCachedAccountInformation = await oauth.hasCachedAccountInformation;
    if(context.mounted){
      ScaffoldMessenger.of(context).hideCurrentSnackBar();
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(
          content:
          Text('HasCachedAccountInformation: $hasCachedAccountInformation'),
        ),
      );
    }
  }

  void logout() async {
    await oauth.logout();
    showMessage('Logged out');
  }
}

Additional Information

  • flutter sdk: >=3.1.5 <4.0.0
  • package: aad_oauth: ^1.0.1
  • OS: Windows 11
  • Gradle Version: 7.4

If possible, it would be greatly appreciated if the solution could be provided as soon as possible as this issue is causing a hindrance in the development process.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions