Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!
We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!
Learn from Guru Rajesh Kumar and double your salary in just one year.
Error:
Try correcting to the name of an existing method, or defining a method named ‘OutlineButton’ in flutter 3.0.0. it isn’t defined for the type
Solution 1:
Yes. That is a breaking change. And it is listed up top in the breaking changes documentation:
The FlatButton, RaisedButton and OutlineButton widgets have been replaced by TextButton, ElevatedButton, and OutlinedButtonrespectively.
source
Flutter – The method ‘forEach’ isn’t defined for the type, The method ‘forEach’ isn’t defined for the type ‘Object’. Try correcting the name to the name of an existing method, or defining a method named ‘forEach’. The method isn’t defined for the type class. 0. Agora local view showing blank screen on Flutter. 0.
Try correcting the name to the name of an existing method, or defining a method named ‘configure’
Question:
I got this error when I try to run flutter app.
The method ‘configure’ isn’t defined for the type ‘FirebaseMessaging’. Try correcting the name to the name of an existing method, or defining a method named ‘configure’.
import 'dart:async'; | |
import 'package:firebase_messaging/firebase_messaging.dart'; | |
import 'package:flutter/cupertino.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:fluttertoast/fluttertoast.dart'; | |
import 'package:mvc_pattern/mvc_pattern.dart'; | |
import '../../generated/l10n.dart'; | |
import '../helpers/custom_trace.dart'; | |
import '../repository/settings_repository.dart' as settingRepo; | |
import '../repository/user_repository.dart' as userRepo; | |
class SplashScreenController extends ControllerMVC with ChangeNotifier { | |
ValueNotifier<Map<String, double>> progress = new ValueNotifier(new Map()); | |
GlobalKey<ScaffoldState> scaffoldKey; | |
final FirebaseMessaging firebaseMessaging = FirebaseMessaging(); | |
SplashScreenController() { | |
this.scaffoldKey = new GlobalKey<ScaffoldState>(); | |
// Should define these variables before the app loaded | |
progress.value = {"Setting": 0, "User": 0}; | |
} | |
@override | |
void initState() { | |
super.initState(); | |
firebaseMessaging.requestNotificationPermissions(const IosNotificationSettings(sound: true, badge: true, alert: true)); | |
configureFirebase(firebaseMessaging); | |
settingRepo.setting.addListener(() { | |
if (settingRepo.setting.value.appName != null && settingRepo.setting.value.appName != '' && settingRepo.setting.value.mainColor != null) { | |
progress.value["Setting"] = 41; | |
progress?.notifyListeners(); | |
} | |
}); | |
userRepo.currentUser.addListener(() { | |
if (userRepo.currentUser.value.auth != null) { | |
progress.value["User"] = 59; | |
progress?.notifyListeners(); | |
} | |
}); | |
Timer(Duration(seconds: 20), () { | |
ScaffoldMessenger.of(scaffoldKey?.currentContext).showSnackBar(SnackBar( | |
content: Text(S.of(state.context).verify_your_internet_connection), | |
)); | |
}); | |
} | |
void configureFirebase(FirebaseMessaging _firebaseMessaging) { | |
try { | |
_firebaseMessaging.configure( | |
onMessage: notificationOnMessage, | |
onLaunch: notificationOnLaunch, | |
onResume: notificationOnResume, | |
); | |
} catch (e) { | |
print(CustomTrace(StackTrace.current, message: e)); | |
print(CustomTrace(StackTrace.current, message: 'Error Config Firebase')); | |
} | |
} | |
Future notificationOnResume(Map<String, dynamic> message) async { | |
print(CustomTrace(StackTrace.current, message: message['data']['id'])); | |
try { | |
if (message['data']['id'] == "orders") { | |
settingRepo.navigatorKey.currentState.pushReplacementNamed('/Pages', arguments: 1); | |
} | |
} catch (e) { | |
print(CustomTrace(StackTrace.current, message: e)); | |
} | |
} | |
Future notificationOnLaunch(Map<String, dynamic> message) async { | |
String messageId = await settingRepo.getMessageId(); | |
try { | |
if (messageId != message['google.message_id']) { | |
if (message['data']['id'] == "orders") { | |
await settingRepo.saveMessageId(message['google.message_id']); | |
settingRepo.navigatorKey.currentState.pushReplacementNamed('/Pages', arguments: 1); | |
} | |
} | |
} catch (e) { | |
print(CustomTrace(StackTrace.current, message: e)); | |
} | |
} | |
Future notificationOnMessage(Map<String, dynamic> message) async { | |
Fluttertoast.showToast( | |
msg: message['notification']['title'], | |
toastLength: Toast.LENGTH_LONG, | |
gravity: ToastGravity.TOP, | |
// backgroundColor: Theme.of(state.context).backgroundColor, | |
// textColor: Theme.of(state.context).hintColor, | |
timeInSecForIosWeb: 5, | |
); | |
} | |
} |
Solution 2:
That widget have been changed to OutlinedButton .
Old Widget was : OutlineButton
Old Theme was : ButtonTheme
New Widget is : OutlinedButton
New Theme is : OutlinedButtonTheme
Here’s an example :
OutlinedButton( | |
style: OutlinedButton.styleFrom( | |
shape: StadiumBorder(), | |
side: BorderSide( | |
width: 2, | |
color: Theme.of(context).colorScheme.primary, | |
), | |
), | |
onPressed: () { dismissDialog(); }, | |
child: Text('New Outlined Button'), | |
), |