|
21 | 21 | - [Prerequisites? 📝](#prerequisites-)
|
22 | 22 | - [0. Project setup](#0-project-setup)
|
23 | 23 | - [\*\*Make sure your `flutter` is up-to-date!](#make-sure-your-flutter-is-up-to-date)
|
| 24 | + - [1. Installing all the needed dependencies](#1-installing-all-the-needed-dependencies) |
| 25 | + - [2. Setting up the responsive framework](#2-setting-up-the-responsive-framework) |
| 26 | + - [3. Create `HomePage` with basic editor](#3-create-homepage-with-basic-editor) |
24 | 27 |
|
25 | 28 |
|
26 | 29 | # Why? 🤷
|
@@ -131,3 +134,134 @@ please follow the instructions in https://stackoverflow.com/questions/52060516/f
|
131 | 134 | You will essentially need to change the `minSdkVersion` parameter
|
132 | 135 | inside `android/app/build.gradle` file
|
133 | 136 | and bump it to a higher version (it is suggested in the error output).
|
| 137 | + |
| 138 | + |
| 139 | +## 1. Installing all the needed dependencies |
| 140 | + |
| 141 | +To implement our application that runs `flutter_quill`, |
| 142 | +we are going to need install some dependencies |
| 143 | +that we're going to be using. |
| 144 | + |
| 145 | +- [`flutter_quill`](https://github.com/singerdmx/flutter-quill), |
| 146 | +the main package with the text editor |
| 147 | +with Delta capabilities. |
| 148 | +- [`flutter_quill_extensions`](https://pub.dev/packages/flutter_quill_extensions), |
| 149 | +needed to use image and video embeds into the editor,. |
| 150 | +- [`file_picker`](https://pub.dev/packages/file_picker), |
| 151 | +so we're able to import files. |
| 152 | +- [`universal_io`](https://pub.dev/packages/universal_io), |
| 153 | +an extended version of `dart.io` that works on all platforms. |
| 154 | +- [`universal_html`](https://pub.dev/packages/universal_html), |
| 155 | +extended version of `dart.html` that is cross-platform. |
| 156 | +- [`responsive_framework`](https://pub.dev/packages/responsive_framework), |
| 157 | +package that will make it easier to make our `Flutter` app responsive. |
| 158 | +- [`path`](https://pub.dev/packages/path) |
| 159 | +and [`path_provider`](https://pub.dev/packages/path_provider), |
| 160 | +needed to find the path of chosen images. |
| 161 | + |
| 162 | +To install of these packages, |
| 163 | +head over to `pubspec.yaml` |
| 164 | +and inside the `dependencies` section, |
| 165 | +add the following lines: |
| 166 | + |
| 167 | +```dart |
| 168 | + flutter_quill: ^7.3.3 |
| 169 | + flutter_quill_extensions: ^0.4.0 |
| 170 | + file_picker: ^5.3.3 |
| 171 | + universal_io: ^2.2.2 |
| 172 | + responsive_framework: ^1.1.0 |
| 173 | + universal_html: ^2.2.3 |
| 174 | + path: ^1.8.3 |
| 175 | + path_provider: ^2.1.0 |
| 176 | +``` |
| 177 | + |
| 178 | +And run `flutter pub get` to download these dependencies. |
| 179 | + |
| 180 | + |
| 181 | +## 2. Setting up the responsive framework |
| 182 | + |
| 183 | +Now that we have all the dependencies we need, |
| 184 | +let's start by setting up all the needed breakpoints |
| 185 | +from the `responsive_framework` |
| 186 | +to make our app responsive |
| 187 | +and *conditionally show elements* |
| 188 | +according to the device size. |
| 189 | + |
| 190 | +Head over to `main.dart` |
| 191 | +and paste the following: |
| 192 | + |
| 193 | +```dart |
| 194 | +import 'package:app/home_page.dart'; |
| 195 | +import 'package:flutter/material.dart'; |
| 196 | +import 'package:responsive_framework/responsive_framework.dart'; |
| 197 | +
|
| 198 | +void main() { |
| 199 | + WidgetsFlutterBinding.ensureInitialized(); |
| 200 | + runApp(App( |
| 201 | + platformService: PlatformService(), |
| 202 | + ),); |
| 203 | +} |
| 204 | +
|
| 205 | +/// Entry gateway to the application. |
| 206 | +/// Defining the MaterialApp attributes and Responsive Framework breakpoints. |
| 207 | +class App extends StatelessWidget { |
| 208 | + const App({required this.platformService, super.key}); |
| 209 | +
|
| 210 | + final PlatformService platformService; |
| 211 | +
|
| 212 | + @override |
| 213 | + Widget build(BuildContext context) { |
| 214 | + return MaterialApp( |
| 215 | + title: 'Flutter Editor Demo', |
| 216 | + builder: (context, child) => ResponsiveBreakpoints.builder( |
| 217 | + child: child!, |
| 218 | + breakpoints: [ |
| 219 | + const Breakpoint(start: 0, end: 425, name: MOBILE), |
| 220 | + const Breakpoint(start: 426, end: 768, name: TABLET), |
| 221 | + const Breakpoint(start: 769, end: 1440, name: DESKTOP), |
| 222 | + const Breakpoint(start: 1441, end: double.infinity, name: '4K'), |
| 223 | + ], |
| 224 | + ), |
| 225 | + theme: ThemeData( |
| 226 | + colorScheme: ColorScheme.fromSeed(seedColor: Colors.white), |
| 227 | + useMaterial3: true, |
| 228 | + ), |
| 229 | + home: HomePage(platformService: platformService), |
| 230 | + ); |
| 231 | + } |
| 232 | +} |
| 233 | +
|
| 234 | +/// Platform service class that tells if the platform is web-based or not |
| 235 | +class PlatformService { |
| 236 | + bool isWebPlatform() { |
| 237 | + return kIsWeb; |
| 238 | + } |
| 239 | +} |
| 240 | +``` |
| 241 | + |
| 242 | +Let's break this down! |
| 243 | + |
| 244 | +- inside `main()`, we initialize the app |
| 245 | +by passing a `platformService`, |
| 246 | +our own small [stubbable](https://en.wikipedia.org/wiki/Method_stub) |
| 247 | +class that will allow us to check in tests whether the device |
| 248 | +is mobile or desktop-based. |
| 249 | +- our app is wrapped in `MaterialApp`. |
| 250 | +In the `builder` parameter, |
| 251 | +we define the `responsive_framework` breakpoints |
| 252 | +to conditionally render widgets according to the device's size. |
| 253 | +- we define the `HomePage` in the `home` parameter. |
| 254 | +This `HomePage` class is not yet defined. |
| 255 | + |
| 256 | +This will fail because `home_page.dart` is not defined. |
| 257 | +Let's do that! 😀 |
| 258 | + |
| 259 | + |
| 260 | +## 3. Create `HomePage` with basic editor |
| 261 | + |
| 262 | +In `lib`, create a file called `home_page.dart` |
| 263 | +and paste the following code. |
| 264 | + |
| 265 | +```dart |
| 266 | +
|
| 267 | +``` |
0 commit comments