fmmalta / no_context_navigation_package

A Flutter package built to navigate between screens without using context (BuildContext)
https://pub.dev/packages/no_context_navigation
MIT License
9 stars 1 forks source link

Bug v2.0.0 'MaterialPageRoute' is not a subtype of type 'Route<Object>?' #6

Open Vasilisk7 opened 3 years ago

Vasilisk7 commented 3 years ago

bug v2 0 0

Testing in clear app. Click 'Go to Detail Screen' and has error

main.dart

import 'package:flutter/material.dart';
import 'package:no_context_navigation/no_context_navigation.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorKey: NavigationService.navigationKey,
      onGenerateRoute: (RouteSettings settings) {
        switch (settings.name) {
          case '/':
            return MaterialPageRoute(builder: (context) => HomeScreen());
          case '/detail_screen':
            return MaterialPageRoute(
                builder: (context) =>
                    DetailScreen(settings.arguments as String));
          default:
            return null;
        }
      },
    );
  }
}

class DetailScreen extends StatelessWidget {
  const DetailScreen(this.message, {Key? key}) : super(key: key);

  final String message;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Detail Screen')),
      body: Center(
        child: Text(message),
      ),
    );
  }
}

class HomeScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            navService.pushNamed('/detail_screen', args: 'From Home Screen');
          },
          child: Text('Go to Detail Screen'),
        ),
      ),
    );
  }
}
Rohithgilla12 commented 2 years ago

Same, any update?