Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
399 views
in Technique[技术] by (71.8m points)

flutter - How to fix InheritedWidget initState issue?

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...