This is the fifth day of my participation in the August More text Challenge. For details, see:August is more challenging

This article about how to achieve the APP’s one-key gray function to say personal feelings, Android is not very understand, no say, asked the students that Android can be set one key gray effect, feel very convenient. 1, modify the related class (UIImage, UIWebview, WKWebView, UIColor, etc.) load method, use runtime method exchange API global modify the current class for the color value requirements, realize the color gray, But the load method has to precede the main method, which means that inside the app if you want to change the color to normal you have to change the load method again and you have to refresh the entire app in order to change the gray color to normal, which is a very difficult and very difficult project. Let’s show you how to use the app flutter to ash.

First, look at the effect

Two, code implementation

Change the component type in the main method to StatefulWidget type, wrap it in a ColorFiltered component, and then set the colorFilter: The colorFilter-mode (color.grey, blendmode.color) attribute (which has many application scenarios) is used to complete the graying effect. Simply declare a status attribute that requires graying and change the status value at a specific time to change the overall app graying effect. Isn’t that simple?

void main() { runApp(MyApp()); } class MyApp extends StatefulWidget { // This widget is the root of your application. @override State<StatefulWidget> createState() { return new MyAppState(); } } class MyAppState extends State<MyApp> with AutomaticKeepAliveClientMixin { bool isGray = true; Future.delayed(Duration(milliseconds: 5000),(){setState(() {isGray = false; }); }); } @override Widget build(BuildContext context) { return isGray ? ColorFiltered(// Set colorFilter: colorFilter. mode(color.grey, blendMode.color), child: MaterialApp( debugShowCheckedModeBanner: false, title: 'Flutter Demo', home: new Scaffold( body: new GeneralFloatOnScreenView(child: new BottomTabbarWidget()), ), ), ) : MaterialApp( debugShowCheckedModeBanner: false, title: 'Flutter Demo', home: new Scaffold( body: new GeneralFloatOnScreenView(child: new BottomTabbarWidget()), ), ); } @override // TODO: implement wantKeepAlive bool get wantKeepAlive => true; }Copy the code

So Flutter is really a custom UI drawing framework and can certainly “do whatever you want”.

3, share how iOS is implemented, to feel 10,000 points of damage critical hit

1. Create categories such as UIImage, UIWebview, WKWebView and UIColor, modify the load method, and realize the gray of the internal color value.

Here’s how it works in plain English: The so-called object-oriented programming is a collection of process oriented programming, but the process oriented programming of c language realization method are derived using the method name to mark it planning to a certain structure, when the structure complicated enough, it becomes the object, so to invoke a method of c language can be unified with the object management, The use of Runtime mechanism can dynamically add, modify, exchange methods for the class, because the classification of the load method is also to execute, then in the inside of some specific method exchange, the original normal color value assignment method into gray color assignment, so as to play a unified purpose of gray. Of course, the graying of web pages requires the native WebView to implement the JS method, that is, to modify the HTML elements under the HTML file style. Filter attribute, so that the graying effect of web pages is completed.

Well, the article is not too much technical content, purely personal use summary, perhaps some friends will have a similar thinking. Write it down, record it, code is bad, god do not spray, if it is helpful to everyone, it is deeply gratified.