I am trying to implement flavors
in my exiting flutter project and i followed the official document but to do this we are using InheritedWidget and there a problem if we use InheritedWidget we need to move code from initState
to dependOnInheritedWidgetOfExactType() or dependOnInheritedElement()
and i do it but there another problem app is showing red screen when we navigate to another pages for few time
That is because we moved code from initState to dependOnInheritedWidgetOfExactType and to fix that we need to add more logic and our project is big and it contains a large number of pages so it is not possible to do now
We only have limited time
so any idea to avoid the usage of dependOnInheritedWidgetOfExactType() or dependOnInheritedElement()
When we are using InheritedWidget or is there any alternative to add flavor without using InheritedWidget?
Be aware about this issue before going to deal with "flutter flavor"
import 'package:flutter/material.dart';
class AppConfig extends InheritedWidget {
AppConfig({this.appDisplayName,this.appInternalId,
Widget child}):super(child: child);
final String appDisplayName;
final int appInternalId;
static AppConfig of(BuildContext context) {
return context.inheritFromWidgetOfExactType(AppConfig);
}
@override
bool updateShouldNotify(InheritedWidget oldWidget) => false;
}
void main() {
var configuredApp = AppConfig(
appDisplayName: "App 1",
appInternalId: 1,
child: MyApp(),
);
mainCommon();
runApp(configuredApp);
}
source
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…