Mahmoud Al-Haroon
Mahmoud Al-Haroon

Reputation: 2449

Try correcting the name to the name of an existing getter, or defining a getter or field named 'isInitialRoute'

I am trying to use the below library:

https://pub.dev/packages/animated_background

called animated_background

when I am trying to run the code, I found the below error:

Compiler message:
lib/helpers/fade_route.dart:12:18: Error: The getter 'isInitialRoute' isn't defined for the class 'RouteSettings'.
 - 'RouteSettings' is from 'package:flutter/src/widgets/navigator.dart' ('/D:/programs/flutter/flutter/packages/flutter/lib/src/widgets/navigator.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'isInitialRoute'.
    if (settings.isInitialRoute)
                 ^^^^^^^^^^^^^^

as this is the below figure which contains the error:

error

and this is the related code:

import 'package:flutter/material.dart';

class FadeRoute<T> extends MaterialPageRoute<T> {
  FadeRoute({ WidgetBuilder builder, RouteSettings settings })
      : super(builder: builder, settings: settings);

  @override
  Widget buildTransitions(BuildContext context,
      Animation<double> animation,
      Animation<double> secondaryAnimation,
      Widget child) {
    if (settings.isInitialRoute)
      return child;
    return new FadeTransition(opacity: animation, child: child);
  }
}

class SimpleFadeRoute<T> extends FadeRoute<T> {
  SimpleFadeRoute({ Widget child, RouteSettings settings })
      : super(builder: (_) => child, settings: settings);
}

Upvotes: 3

Views: 41377

Answers (2)

Shehzad Ahmad
Shehzad Ahmad

Reputation: 11

Try flutter clean and flutter pub get, it worked for me.

Upvotes: 1

Claudio Redi
Claudio Redi

Reputation: 68440

That property was removed from RouteSettings. See the following link for an alternative.

We removed the isInitialRoute property from RouteSetting as part of refactoring, and provided the onGenerateInitialRoutes API for full control of initial routes generation.

There are different ways to migrate this change. One way is to set the initial route name to a fixed value and generate a specific route (FakeSplashRoute in the above example) for the route name.

MaterialApp(
  initialRouteName: ‘fakeSplash’,
  onGenerateRoute: (RouteSetting setting) {
    if (setting.name == ‘fakeSplash’)
      return FakeSplashRoute();
    else
      return RealRoute(setting);
  }
)

If there is a more complicated use case, you can use the new API, onGenerateInitialRoutes, in MaterialApp or CupertinoApp.

MaterialApp(
  onGenerateRoute: (RouteSetting setting) {
    return RealRoute(setting);
  },
  onGenerateInitialRoutes: (String initialRouteName) {
    return <Route>[FakeSplashRoute()];
  }
)

Upvotes: 1

Related Questions