Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tratum opened this issue Feb 18, 2024 · 9 comments

Comments

@tratum
Copy link
Contributor

tratum commented Feb 18, 2024

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.

@tratum tratum changed the title Error: Method 'PopScope' isn't defined in 'RequestCode' class Method 'PopScope' isn't defined in 'RequestCode' class Feb 18, 2024
@nguyenlong1999
Copy link

I also had the same problem. Pls help me!

@tratum
Copy link
Contributor Author

tratum commented Feb 19, 2024

Can you take a look at this @josemiguelvarela and @loetsphi

@ahmadkhedr
Copy link

Same here

@ahmadkhedr
Copy link

Maybe this is not the best solution, but after downgrading the package to 0.4.4 it works as expected...not the best solution but it at least could help in the development process until the issue is solved in the latest version

@loetsphi
Copy link
Contributor

@tratum WillPopScope has been deprecated, which is the reason we changed it in this package, but i see the issue as per https://docs.flutter.dev/release/breaking-changes/android-predictive-back Flutter 3.16 is necessary for the Replacement PopScope, which probably not everyone has upgraded to.
The change was introduced with 1.0.1 so you should also be able to use 1.0.0. Or upgrade your Flutter to at least 3.16.

Sorry for this, maybe we should have waited a bit longer with the switch.

@tratum
Copy link
Contributor Author

tratum commented Feb 20, 2024

Thanks @loetsphi , it's functioning now, although I'm encountering another problem. I'm uncertain about it but will notify you if it persists.

@tratum
Copy link
Contributor Author

tratum commented Feb 20, 2024

also thnks @ahmadkhedr for helping out

@tratum
Copy link
Contributor Author

tratum commented Mar 1, 2024

Should i close the issue @loetsphi

@loetsphi loetsphi pinned this issue Mar 1, 2024
@loetsphi
Copy link
Contributor

loetsphi commented Mar 1, 2024

You are right, it is resolved, but further people with the same problem should still be able to see it, so i pinned it.

@loetsphi loetsphi closed this as completed Mar 1, 2024
@loetsphi loetsphi changed the title Method 'PopScope' isn't defined in 'RequestCode' class Method 'PopScope' isn't defined in 'RequestCode' class (resolution: use Flutter >3.16.0 or aad_oauth <=1.0.0) Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants