Page life cycle statistics method, equipment and storage medium based on Flutter
By introducing the full life cycle statistics method of pages in Flutter, including monitoring of initialization, pause, recovery and destruction status, the problem of inaccurate statistics on the number of page visits and durations in the existing technology is solved, and accurate statistics of page access data is achieved .
Patent Information
- Application Number
- CN202011222460.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-05
- Publication Date
- 2024-11-12
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing Flutter page component lifecycle method cannot fully count the number of page accesses and durations, especially when the page is in a pause and recovery state, resulting in less or larger statistics and cannot meet business needs.
Provides Flutter-based page full life cycle statistics method, including monitoring of four states: initialization, pause, recovery and destruction. By rewriting the component listener and navigation listener, accurately counting the number of page accesses and durations to ensure the accuracy of data.
It realizes accurate statistics on the number of page visits and durations, meets business needs, and avoids deviations in statistical results.
Smart Images

Figure CN112463520B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, device and storage medium for counting the entire life cycle of a page based on Flutter. Background Art
[0002] By analyzing the data obtained from user behavior monitoring, application providers can understand user behavior habits in more detail and clearly, thereby finding problems with application provider products or marketing such as websites, mobile applications, and promotion channels, which helps application providers develop products that better meet user needs and discover high-conversion rate pages. Therefore, user page usage data analysis is extremely important, that is, after obtaining basic data on platform visits such as website or APP pages, the relevant data is counted and analyzed to find out the rules of user visits to websites or APP platforms, and these rules are combined with product optimization strategies or online marketing strategies, so as to find out possible problems in current product design or online marketing activities, and provide a basis for further optimizing products or revising online marketing strategies.
[0003] Flutter is an open source UI toolkit from Google Inc. It is a cross-platform development framework that helps developers efficiently build beautiful multi-platform applications through a set of code bases, supporting mobile terminals (iOS, Android), Web, desktop and embedded platforms. As we all know, after a product is developed and delivered to users, in order to better collect user usage behavior and adjust and optimize the product, data statistics are needed. Among them, page behavior statistics are very important and the most basic, which obtains user page usage behavior data. The page usage behavior data includes the number of page visits, page access paths, page access duration, etc.
[0004] In the Flutter development framework, everything is a widget. If you want to count the above page behaviors, you can only do so in the page component StatefulWidget lifecycle method provided by the Flutter SDK. The page component lifecycle refers to the complete process of a page from creation to initialization, suspension, resumption, and destruction. The existing page component lifecycle methods include the state initialization method initState and the destruction method onDispose, which is recorded as page entry in the state initialization method and page exit in the destruction method.
[0005] The existing page usage behavior data statistics method, that is, the page component life cycle method, has the following shortcomings: First, the life cycle method provided by the Flutter framework only includes the initialization method initState and the destruction method onDispose. When the page is in the intermediate state such as pause and resume, there is no corresponding life cycle method for statistics, resulting in the number of page visits counted being less than the actual number and the page visit duration being longer than the actual number, which cannot fully meet business needs. Specifically, the user first enters the first-level page, at which time the state of the first-level page is called "initialization"; through a certain operation to enter the second-level page, the first-level page is not visible to the user but is not destroyed, at which time the state of the first-level page is called "pause"; when the user returns from the second-level page to the first-level page, the first-level page is visible to the user again, at which time the state of the first-level page is called "recovery"; if the user then exits the first-level page through a certain operation, the state of the first-level page is called "destruction". The entire life cycle of a page consists of four states: initialization, pause, resume, and destruction.
[0006] Based on this, the technical problem to be solved by the present invention is to avoid the situation where the number of page accesses counted is too small compared with the actual number, and the page access duration is too large compared with the actual number, which cannot fully meet the business needs. Summary of the invention
[0007] In response to the above problems, the present invention provides a page full life cycle statistics method, device and storage medium based on Flutter. The present invention supports full life cycle monitoring of Flutter page component initialization, suspension, resumption and destruction, and can accurately count the number of page visits, page access paths, page access duration, etc., to fully meet business needs.
[0008] On the one hand, the present invention provides a page full life cycle statistics method based on Flutter, and its technical solution is as follows:
[0009] A page life cycle statistics method based on Flutter, wherein the page life cycle includes initialization state, pause state, resume state and destruction state, and is characterized by:
[0010] When a page changes from a paused state to a resumed state, the time between the paused state and the resumed state is not counted in the actual usage time of the page;
[0011] When a page is restored from a paused state, the number of visits to the page is counted only once.
[0012] Furthermore, when a page enters the initialization state, the time the page is in the initialization state is counted into the actual usage time of the page; when the page is in the paused state, the time the page is in the paused state is not counted into the actual usage time of the page; when the page is in the resumed state, the time the page is in the resumed state is counted into the actual usage time of the page; when the page exits and enters the destruction state, the time the page is in the destruction state is not counted into the actual usage time of the page.
[0013] Furthermore, when the user returns to the system desktop or jumps to other applications, the application lifecycle state change method of the component listener is rewritten to obtain whether the current application is in a resumed state or a paused state for the user when the application state changes; when the user operates the page, the corresponding page operation method is triggered, and when the page operation method is invoked, at least one parameter is passed in; and by obtaining the page indicated in the parameter, it is determined whether the page is in a paused state or a resumed state.
[0014] Furthermore, when the user opens the current page for the first time, the initialization method is triggered, and the current page is in the initialization state. When the user exits the current page, the destruction method is triggered, and the current page is in the destruction state.
[0015] Furthermore, the page operation includes opening a page, exiting a page, removing a page and replacing a page; the page operation method includes a page opening method, an exit method, a removal method and a replacement method.
[0016] Further, when the open method or the replace method is called, and the page indicated by the parameter is the current page, it is determined that the current page is about to enter a pause state;
[0017] Furthermore, when the exit method or the remove method is called, and the page indicated by the parameter is the current page, it is determined that the current page is about to enter a recovery state.
[0018] Furthermore, the component listener is responsible for monitoring the pause state and resume state when switching between different applications; the navigation listener monitors the pause state and resume state when switching between all pages in the same application.
[0019] On the other hand, a page life cycle statistics device based on Flutter is also provided, characterized in that the device includes a processor and a memory, the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement any of the above-mentioned page life cycle statistics methods.
[0020] On the other hand, a computer-readable storage medium is also provided, characterized in that the storage medium stores at least one instruction, at least one program, code set or instruction set, and the at least one instruction, at least one program, code set or instruction set is loaded and executed by a processor to implement any of the above-mentioned page life cycle statistics methods.
[0021] The Flutter-based page full life cycle statistics method, device, and storage medium provided in this application have the following technical effects:
[0022] The present invention provides a technical solution for a page full life cycle statistics method based on Flutter, that is, when a page changes from a paused state to a resumed state, the time between the paused state and the resumed state of the page is not included in the actual usage time of the page; when the page changes from a paused state to a resumed state, the number of visits to the page is counted only once. This can avoid the counted number of page visits being too small compared to the actual number, and the page visit duration being too large compared to the actual number. Based on the full life cycle statistics solution of the page component of the present invention, the number of page visits, page access paths, page access durations, etc. can be accurately counted to fully meet business needs. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 This is a schematic diagram of a Flutter-based page full life cycle statistics method provided by an embodiment of the present invention.
[0024] Figure 2 It is a workflow diagram provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0025] In order to enable those skilled in the art to better understand the technical solution of the present invention, the technical solution in the embodiment of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiment of the present invention. Obviously, the described embodiment is only an embodiment of a part of the present invention, not all of the embodiments, and this embodiment is only used to explain the present invention and does not constitute a limitation on the scope of protection of the present invention. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without making creative work should fall within the scope of protection of this application.
[0026] Those skilled in the art will appreciate that, unless otherwise stated, the singular forms "a", "an", "said" and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present invention refers to the presence of the features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof.
[0027] It will be understood by those skilled in the art that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as generally understood by those skilled in the art in the art to which the present invention belongs. It should also be understood that terms such as those defined in general dictionaries should be understood to have meanings consistent with the meanings in the context of the prior art, and will not be interpreted with idealized or overly formal meanings unless specifically defined as herein.
[0028] Those skilled in the art can understand that the terms "page", "application", "page access", "page component life cycle" and the like used herein are applicable to mobile terminals or Web or desktop or embedded platforms, and the "application" can be application software or system software. The "device" described in the present invention may include: computers, tablet computers, mobile phones, wearable devices (such as bracelets, etc.), and the like.
[0029] First, a brief description of the technical terms that may be involved in the present invention is given:
[0030] Flutter: It is an open source UI toolkit from Google Inc. and a cross-platform development framework that helps developers efficiently build exquisite multi-platform applications through a set of code bases. It supports mobile (iOS, Android), Web, desktop and embedded platforms.
[0031] Page component life cycle: refers to the complete process of a page from creation to initialization, suspension, resumption, and destruction.
[0032] After a product is developed and delivered to the user, data statistics are needed to better collect user behavior and adjust and optimize the product. Among them, the most important and basic is page behavior statistics, including page visit counts, page visit paths, page visit duration, etc.
[0033] In the Flutter development framework, everything is a widget. If you want to count the above page behaviors, you can only do so in the StatefulWidget lifecycle method of the page component provided by the Flutter SDK, including the state initialization method initState and the destruction method onDispose, that is, the state initialization method is recorded as page entry, and the destruction method is recorded as page exit.
[0034] The following describes a specific embodiment of the method for counting the entire life cycle of a page based on Flutter. Figure 1This is a schematic diagram of a page life cycle statistics method based on Flutter of the present invention. The present invention provides method operation steps as described in this embodiment or flowchart, but more or fewer operation steps may be included based on conventional or non-creative labor. The order of steps listed in the embodiment is only one way of executing the order of many steps and does not represent the only execution order. The execution subject of the method may be a terminal, and the terminal may specifically include software running in a physical device, such as an application installed on the device, and may also include at least one of the physical devices of the type of a smartphone, a tablet computer, a digital assistant, a smart wearable device, etc., with an application installed. Specifically, an operating system runs on the terminal, and the operating system may be an operating system such as iOS (Apple mobile terminal operating system) or an Android operating system.
[0035] The lifecycle methods provided by the Flutter framework only include the initialization method initState and the destruction method onDispose. When the page is in an intermediate state such as pause or resume, there is no corresponding lifecycle method for statistics. As a result, the number of page visits counted is less than the actual number, and the page visit duration is longer than the actual number, which cannot fully meet business needs.
[0036] Embodiment 1 of the present invention, as Figure 1 The method for counting the entire life cycle of a page based on Flutter, the entire life cycle of the page in the present invention includes an initialization state, a pause state, a resume state, and a destruction state, and the specific implementation method is as follows:
[0037] S01: When a page changes from a paused state to a resumed state, the time between the paused state and the resumed state of the page is not counted into the actual usage time of the page.
[0038] S02: When a page changes from a paused state to a resumed state, the number of times the page is accessed is counted as only one.
[0039] Specifically, the user first enters the first-level page, and the state of the first-level page is called "initialization"; through a certain operation, the user enters the second-level page, and the first-level page is invisible to the user but not destroyed. At this time, the state of the first-level page is called "pause"; when the user returns to the first-level page from the second-level page, the first-level page is visible to the user again, and the state of the first-level page is called "recovery"; if the user then exits the first-level page through a certain operation, the state of the first-level page is called "destruction". The full life cycle of a page consists of four states: initialization, pause, recovery, and destruction. The time from the pause state to the recovery state of the first-level page is not included in its actual usage time, otherwise the page access time statistics will be larger than the actual time. From the pause state to the recovery state of the first-level page, it is counted as one page entry, otherwise the number of page visits will be smaller than the actual time. The first-level page and the second-level page have their own complete life cycles. The entry of the second-level page will cause the first-level page to change from visible to invisible, so that the life cycle of the first-level page changes from initialization to pause. In order to illustrate the problem, only the life cycle of the first-level page is concerned here.
[0040] When a page enters the initialization state, the time the page is in the initialization state is counted into the actual usage time of the page; when the page is in the paused state, the time the page is in the paused state is not counted into the actual usage time of the page; when the page is in the resumed state, the time the page is in the resumed state is counted into the actual usage time of the page; when the page exits and enters the destruction state, the time the page is in the destruction state is not counted into the actual usage time of the page.
[0041] The accuracy of the statistical data on the actual usage time of users entering a page is related to the effectiveness of the page's full life cycle monitoring. The following introduces the monitoring method for the page's full life cycle.
[0042] The method for monitoring the entire life cycle of a page described in the present invention: when the user returns to the system desktop or jumps to other applications, the application life cycle state change method of the component listener is rewritten to obtain whether the current application is in a resumed state or a paused state for the user when the application state changes; when the user operates the page, the corresponding page operation method is triggered, and when the page operation method is invoked, at least one parameter is passed in; by obtaining the page indicated in the parameter, it is determined whether the page is in a paused state or a resumed state.
[0043] It should be noted here that the pause and resume states when switching between applications are realized by monitoring the states of different applications through the component listener WidgetsBindingObserver. That is, when the user returns to the system desktop or jumps to other applications, the application lifecycle state change method didChangeAppLifecycleState of the component listener will be triggered. By overriding this method, it is possible to obtain in real time whether the current application is resumed (application visible) or paused (application invisible) to the user when the application state changes.
[0044] Specifically, if the application state changes from the resume state (visible state) to the pause state, such as pressing the Home button to return to the desktop or switch to other applications, then the top-level page of the application also becomes the pause state accordingly; if the application state changes from the pause state to the resume state (visible state), such as clicking the application icon from the desktop to open the application again or switching back to the application from other applications, then the top-level page of the application also becomes the resume state (visible state) accordingly.
[0045] It should also be noted that the navigation listener GlobalNavigatorObserver is used to globally monitor all page switching events in the application to achieve the pause and resume state when switching pages. That is, when the user opens a page, exits a page, removes a page, or replaces a page, the corresponding opening method didPush, exit method didPop, removal method didRemove, and replacement method didReplace will be triggered.
[0046] As can be seen from these method signatures, when the Flutter framework invokes these methods, it will pass in route (Route <dynamic>Type) and previousRoute(Route <dynamic>Type), the present invention determines whether the page is in a paused or resumed state by obtaining the page indicated in the previousRoute parameter.
[0047] Specifically: when the opening method didPush and the replacement method didReplace are called, if the page indicated by the parameter previousRoute is the current page, then the current page is about to enter the pause state; when the exit method didPop and the removal method didRemove are called, if the page indicated by the parameter previousRoute is the current page, then the current page is about to enter the resume state.
[0048] When the user opens the current page for the first time, the initialization method will be triggered, and the current page is in the initialization state. When the user exits the current page, the destruction method will be triggered, and the current page is in the destruction state.
[0049] It should be noted here that the page state abstract class BasePageState<T extends StatefulWidget> It is the parent class of all page components. The present invention uses the page state abstract class BasePageState<T extendsStatefulWidget> To implement page initialization. When the user opens the current page for the first time, the initialization method initState will be triggered, and the current page is in the initialization state.
[0050] Similarly, the present invention uses the page state abstract class BasePageState<T extends StatefulWidget> To achieve the page destruction state. When the user exits the current page, the destruction method dispose will be triggered, and the current page is in the destroyed state.
[0051] The page operation includes opening a page, exiting a page, removing a page and replacing a page; the page operation method includes a page opening method, an exit method, a removal method and a replacement method.
[0052] When the open method or the replace method is called, the page indicated by the parameter is the current page, and it is determined that the current page is about to enter the pause state; when the exit method or the remove method is called, the page indicated by the parameter is the current page, and it is determined that the current page is about to enter the resume state.
[0053] The component listener is responsible for monitoring the pause and resume states when switching between different applications; the navigation listener monitors the pause and resume states when switching between all pages in the same application.
[0054] In addition, the page lifecycle global listener BasePageStateObservable provides a globally unique page component lifecycle monitoring outlet within the application, where statistical data can be uploaded.
[0055] The listener provides four interface methods: page entry method onInitState(State state), page pause method onPause(State state), page recovery method onResume(State state), and page destruction method onDispose(State state). The developer needs to pass the page state abstract class BasePageState into the listener instance object.
[0056] When the page life cycle changes, the page state abstract class BasePageState calls the four methods corresponding to the instance object, which is the interface callback. Developers can obtain the page name indicated by the parameter state (state.widget.toString) in these four interface methods to upload statistical data without writing cumbersome embedding code.
[0057] The overall workflow of the present invention involves component listener WidgetsBindingObserver, navigation listener GlobalNavigatorObserver, page state abstract class BasePageState<Textends StatefulWidget> , the page life cycle global listener BasePageStateObservable, the method flow of the above four parts is as follows Figure 2 shown.
[0058] Open the application, the Flutter framework starts, executes the runApp method of the application, and returns the material application component MaterialApp to the Flutter framework.
[0059] Pass the global navigation listener GlobalNavigatorObserver instance object to the navigation listener construction parameter navigatorObservers of the material application component MaterialApp to start monitoring the switching events of all pages in the application.
[0060] Generate a page lifecycle global listener BasePageStateObservable instance object and pass it to the page state abstract class BasePageState.
[0061] Enter the page and trigger the corresponding page entry method onInitState (for clear description, recorded as "page entry method A"). In this method, call the addObserver method of the component binding class WidgetsBinding provided by the Flutter architecture to pass in the component listener WidgetsBindingObserver instance object to start application status monitoring.
[0062] At the same time, the page entry method onInitState(State state) of the page life cycle global listener BasePageStateObservable instance object is triggered in the page entry onInitState method (for clear description, recorded as "page entry method B").
[0063] Subsequent page pauses, resumes, and destructions caused by page switching and application switching will trigger the page pause method onPause(State state), page resume method onResume(State state), and page destruction method onDispose(State state) of the lifecycle global listener BasePageStateObservable instance object.
[0064] In the corresponding method of the BasePageStateObservable instance object of the lifecycle global listener, upload statistical data.
[0065] The statistical background is used for data analysis and display.
[0066] Embodiment 2 of the present invention provides a page life cycle statistics device based on Flutter, characterized in that the device includes a processor and a memory, the memory stores at least one instruction, at least one program, a code set, or an instruction set, and the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by the processor to implement any of the page life cycle statistics methods described above.
[0067] Embodiment 3 of the present invention provides a computer-readable storage medium, characterized in that the storage medium stores at least one instruction, at least one program, code set or instruction set, and the at least one instruction, at least one program, code set or instruction set is loaded by a processor and executed by any of the page life cycle statistics methods described above.
[0068] Optionally, in an embodiment of the present application, the above-mentioned storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store program codes.
[0069] The present invention provides a technical solution for a page full life cycle statistics method based on Flutter, and the full life cycle of the page component includes initialization, pause, resume and destruction. When the page is in an intermediate state such as pause or resume, there is no corresponding life cycle method for statistics, resulting in the number of page accesses counted being less than the actual number, and the page access duration being longer than the actual number, which cannot fully meet business needs. The full life cycle monitoring solution of the page component based on the present invention is conducive to accurately counting the number of page accesses, page access paths, page access durations, etc., to fully meet business needs.
[0070] It should be noted that the above-mentioned sequence of the embodiments of the present application is for description only and does not represent the advantages and disadvantages of the embodiments. The above-mentioned specific embodiments of this specification are described. Other embodiments are within the scope of the attached claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0071] The same or similar parts between the various embodiments in this specification can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, equipment, and storage medium embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0072] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware, or may be accomplished by instructing the relevant hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.
[0073] The basic principles, main features and advantages of the present invention are shown and described above. Those skilled in the art should understand that the above description is only a preferred embodiment of the present invention, and the present invention is not limited to the above embodiment. The above embodiment and the description are only to illustrate the principle of the present invention. Without departing from the spirit and scope of the present invention, the present invention may have various changes and improvements, and these changes and improvements fall within the scope of the present invention claimed for protection. The scope of protection claimed by the present invention is defined by the attached claims and their equivalents.< / dynamic> < / dynamic>
Claims
1. A page life cycle statistics method based on Flutter, wherein the page life cycle includes initialization state, pause state, resume state and destruction state, and is characterized by: When a page changes from a paused state to a resumed state, the time between the paused state and the resumed state is not counted in the actual usage time of the page; When a page is restored from the paused state, the number of visits to the page is counted as only one; When a page enters the initialization state, the time the page is in the initialization state is counted into the actual usage time of the page; When a page is in a paused state, the time the page is in a paused state is not counted into the actual usage time of the page; When a page is in a restored state, the time the page is in the restored state is counted into the actual usage time of the page; When a page exits and enters the destroyed state, the time the page is in the destroyed state is not counted into the actual usage time of the page; When the user returns to the system desktop or jumps to other applications, the application lifecycle state change method didChangeAppLifecycleState of the component listener will be triggered. By overriding the application lifecycle state change method of the component listener, it is possible to obtain whether the current application is in a resumed state or a paused state for the user when the application state changes; when the user operates the page, the corresponding page operation method will be triggered. When the page operation method is invoked, at least one parameter will be passed in, and the parameter is the previousRoute parameter; by obtaining the page indicated in the parameter, it is determined whether the page is in a paused state or a resumed state.
2. The method for counting the entire life cycle of a page based on Flutter according to claim 1 is characterized in that: When the user opens the current page for the first time, the initialization method will be triggered, and the current page is in the initialization state. When the user exits the current page, the destruction method will be triggered, and the current page is in the destruction state.
3. The Flutter-based page full life cycle statistics method according to claim 1 is characterized in that: The page operation includes opening a page, exiting a page, removing a page and replacing a page; the page operation method includes a page opening method, an exit method, a removal method and a replacement method.
4. The method for counting the entire life cycle of a page based on Flutter according to claim 3 is characterized in that: When the open method and the replace method are called, the page indicated by the parameter is the current page, and it is determined that the current page is about to enter a pause state.
5. According to a Flutter-based page full life cycle statistics method according to claim 3, it is characterized in that: When the exit method or the remove method is called, the page indicated by the parameter is the current page, and it is determined that the current page is about to enter the recovery state.
6. The method for counting the entire life cycle of a page based on Flutter according to claim 1 is characterized in that: The component listener is responsible for monitoring the pause and resume states when switching between different applications; the navigation listener monitors the pause and resume states when switching between all pages in the same application.
7. A page full life cycle statistics device based on Flutter, characterized by: The device includes a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the page life cycle statistics method as described in any one of claims 1 to 6.
8. A computer-readable storage medium, characterized in that: The storage medium stores at least one instruction, at least one program, code set or instruction set, and the at least one instruction, at least one program, code set or instruction set is loaded by the processor and executed by the page life cycle statistics method as described in any one of claims 1 to 6.
