Skip to content

Commit a2213d4

Browse files
committed
feat: Adding main.dart section. #1
1 parent dc862fc commit a2213d4

File tree

9 files changed

+148
-33
lines changed

9 files changed

+148
-33
lines changed

README.md

+134
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
- [Prerequisites? 📝](#prerequisites-)
2222
- [0. Project setup](#0-project-setup)
2323
- [\*\*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)
2427

2528

2629
# Why? 🤷‍
@@ -131,3 +134,134 @@ please follow the instructions in https://stackoverflow.com/questions/52060516/f
131134
You will essentially need to change the `minSdkVersion` parameter
132135
inside `android/app/build.gradle` file
133136
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+
```

integration_test/widget_test.mocks.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Do not manually edit this file.
44

55
// ignore_for_file: no_leading_underscores_for_library_prefixes
6-
import 'package:app/home_page.dart' as _i2;
6+
import 'package:app/main.dart' as _i2;
77
import 'package:mockito/mockito.dart' as _i1;
88

99
// ignore_for_file: type=lint

lib/home_page.dart

+1-8
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import 'dart:async';
22
import 'dart:io';
33
import 'dart:ui';
44

5+
import 'package:app/main.dart';
56
import 'package:file_picker/file_picker.dart';
6-
import 'package:flutter/foundation.dart';
77
import 'package:flutter/material.dart';
88
import 'package:flutter_quill/extensions.dart';
99
import 'package:flutter_quill/flutter_quill.dart' hide Text;
@@ -331,11 +331,4 @@ class HomePageState extends State<HomePage> {
331331
class ImageFilePicker {
332332
Future<FilePickerResult?> pickImage() => FilePicker.platform.pickFiles(type: FileType.image);
333333
}
334-
335-
/// Platform service class that tells if the platform is web-based or not
336-
class PlatformService {
337-
bool isWebPlatform() {
338-
return kIsWeb;
339-
}
340-
}
341334
// coverage:ignore-end

lib/main.dart

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:app/home_page.dart';
2+
import 'package:flutter/foundation.dart';
23
import 'package:flutter/material.dart';
34
import 'package:responsive_framework/responsive_framework.dart';
45

@@ -39,3 +40,12 @@ class App extends StatelessWidget {
3940
);
4041
}
4142
}
43+
44+
// coverage:ignore-start
45+
/// Platform service class that tells if the platform is web-based or not
46+
class PlatformService {
47+
bool isWebPlatform() {
48+
return kIsWeb;
49+
}
50+
}
51+
// coverage:ignore-end

lib/web_embeds/web_embeds.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import 'package:app/home_page.dart';
2+
import 'package:app/main.dart';
33
import 'package:flutter/cupertino.dart';
44
import 'package:flutter_quill/flutter_quill.dart';
55
import 'package:flutter_quill_extensions/flutter_quill_extensions.dart';

pubspec.lock

-16
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,6 @@ packages:
185185
url: "https://pub.dev"
186186
source: hosted
187187
version: "0.17.3"
188-
cupertino_icons:
189-
dependency: "direct main"
190-
description:
191-
name: cupertino_icons
192-
sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be
193-
url: "https://pub.dev"
194-
source: hosted
195-
version: "1.0.5"
196188
dart_style:
197189
dependency: transitive
198190
description:
@@ -297,14 +289,6 @@ packages:
297289
url: "https://pub.dev"
298290
source: hosted
299291
version: "0.9.3"
300-
filesystem_picker:
301-
dependency: "direct main"
302-
description:
303-
name: filesystem_picker
304-
sha256: cf790e033b3e0c07b5bc9f71458b39f1f45017641aae508ffdfb86a59baa0c1d
305-
url: "https://pub.dev"
306-
source: hosted
307-
version: "3.1.0"
308292
fixnum:
309293
dependency: transitive
310294
description:

pubspec.yaml

-5
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,9 @@ dependencies:
3131
flutter:
3232
sdk: flutter
3333

34-
35-
# The following adds the Cupertino Icons font to your application.
36-
# Use with the CupertinoIcons class for iOS style icons.
37-
cupertino_icons: ^1.0.2
3834
flutter_quill: ^7.3.3
3935
flutter_quill_extensions: ^0.4.0
4036
file_picker: ^5.3.3
41-
filesystem_picker: ^3.1.0
4237
universal_io: ^2.2.2
4338
responsive_framework: ^1.1.0
4439
universal_html: ^2.2.3

test/widget_test.dart

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// gestures. You can also use WidgetTester to find child widgets in the widget
66
// tree, read text, and verify that the values of widget properties are correct.
77

8-
import 'package:app/home_page.dart';
98
import 'package:flutter/material.dart';
109
import 'package:flutter_quill/flutter_quill.dart';
1110
import 'package:flutter_quill_extensions/embeds/toolbar/image_button.dart';

test/widget_test.mocks.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Do not manually edit this file.
44

55
// ignore_for_file: no_leading_underscores_for_library_prefixes
6-
import 'package:app/home_page.dart' as _i2;
6+
import 'package:app/main.dart' as _i2;
77
import 'package:mockito/mockito.dart' as _i1;
88

99
// ignore_for_file: type=lint

0 commit comments

Comments
 (0)