A Complete Example¶
Key Points of the App
This app illustrates the implementation of the following aspects:
- Usage of the NavigationBar
- How to distribute the code in different packages for better maintenance and separation of functional concerns
- How to use the SnackBar in different Widgets and across the app
- Undo-action in the SnackBar
- Usage of Futures in handlers
- Fetch data from an endpoint via HTTP(S)
- Store data in local collections
- Process JSON asynchronously
- Global state management using June
- Separte application data in model-classes
- Combine model-classes and widgets using June as state manager
- Customize FloatingActionButtons on different screens using a single Scaffold
- Using more than one FloatingActionButton
- Selectively display different FloatingActionButtons based on the selected NavigationBar item
Overview¶
The following app demonstrates implementation options for some of the main flutter language features that should be acquired by students in the course. It is intended to help students incorporate those features into their semester projects.
Source code of the app
The app’s source code is available via GitHub.
Architecture¶
The app consists of three screens (aka pages or routes in Flutter nomenclature):
- Counter – alter a counter variable as part of the app state
- User – fetch user data from a remote endpoint and display it in a table view
- User List – asynchronously add fetched users to a list using
ListView.builder()
The source code is separated in several packages according to its purpose:
model
– contains the models (aka data structures) for global app state objects. These classes represent the app’s entities, i.e., its data objectspages
– contains the single screens of the appservices
– hosts the service classes (e.g. fetching or storage methods etc.)state
– these are the actual state classes needed by June (they are extendingJuneState
)widgets
– contains individually defined widget classes; currently empty.
I recommend that you use a similar structure in/for your projects.
Source Code¶
Please note: I do not display the source code of all project files but rather those that are most informative. The complete source code can be obtained from the GitHub-repository.
model/user.dart¶
pages/counter_page.dart¶
pages/single_user_page.dart¶
pages/user_list_page.dart¶
state/counter.dart¶
state/user_state.dart¶
main.dart¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|