From 2170ea9e50af6e64c7e03fb32a7a0b79d2afbcda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lui=CC=81s=20Arteiro?= Date: Mon, 25 Sep 2023 12:44:06 +0100 Subject: [PATCH] feat: Adding heading styles options. #8 --- lib/home_page.dart | 72 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 9 deletions(-) diff --git a/lib/home_page.dart b/lib/home_page.dart index 81239c9..cb31ea8 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -151,12 +151,34 @@ class HomePageState extends State { fontSize: 32, color: Colors.black, height: 1.15, - fontWeight: FontWeight.w300, + fontWeight: FontWeight.w600, ), const VerticalSpacing(16, 0), const VerticalSpacing(0, 0), null, ), + h2: DefaultTextBlockStyle( + const TextStyle( + fontSize: 24, + color: Colors.black87, + height: 1.15, + fontWeight: FontWeight.w600, + ), + const VerticalSpacing(8, 0), + const VerticalSpacing(0, 0), + null, + ), + h3: DefaultTextBlockStyle( + const TextStyle( + fontSize: 20, + color: Colors.black87, + height: 1.25, + fontWeight: FontWeight.w600, + ), + const VerticalSpacing(8, 0), + const VerticalSpacing(0, 0), + null, + ), sizeSmall: const TextStyle(fontSize: 9), subscript: const TextStyle( fontFamily: 'SF-UI-Display', @@ -191,12 +213,34 @@ class HomePageState extends State { fontSize: 32, color: Colors.black, height: 1.15, - fontWeight: FontWeight.w300, + fontWeight: FontWeight.w600, ), const VerticalSpacing(16, 0), const VerticalSpacing(0, 0), null, ), + h2: DefaultTextBlockStyle( + const TextStyle( + fontSize: 24, + color: Colors.black87, + height: 1.15, + fontWeight: FontWeight.w600, + ), + const VerticalSpacing(8, 0), + const VerticalSpacing(0, 0), + null, + ), + h3: DefaultTextBlockStyle( + const TextStyle( + fontSize: 20, + color: Colors.black87, + height: 1.25, + fontWeight: FontWeight.w600, + ), + const VerticalSpacing(8, 0), + const VerticalSpacing(0, 0), + null, + ), sizeSmall: const TextStyle(fontSize: 9), ), embedBuilders: [...defaultEmbedBuildersWeb], @@ -215,7 +259,7 @@ class HomePageState extends State { // `onImagePickCallback` is called after image is picked on mobile platforms onImagePickCallback: _onImagePickCallback, - // `webImagePickImpl` is called after image is picked on the web + // `webImagePickImpl` is called after image is picked on the web webImagePickImpl: _webImagePickImpl, // defining the selector (we only want to open the gallery whenever the person wants to upload an image) @@ -240,6 +284,12 @@ class HomePageState extends State { controller: _controller!, undo: false, ), + SelectHeaderStyleButton( + controller: _controller!, + axis: Axis.horizontal, + iconSize: toolbarIconSize, + attributes: const [Attribute.h1, Attribute.h2, Attribute.h3], + ), ToggleStyleButton( attribute: Attribute.bold, icon: Icons.format_bold, @@ -291,12 +341,12 @@ class HomePageState extends State { /// Renders the image picked by imagePicker from local file storage /// You can also upload the picked image to any server (eg : AWS s3 /// or Firebase) and then return the uploaded image URL. - /// + /// /// It's only called on mobile platforms. Future _onImagePickCallback(File file) async { - final appDocDir = await getApplicationDocumentsDirectory(); - final copiedFile = await file.copy('${appDocDir.path}/${basename(file.path)}'); - return copiedFile.path.toString(); + final appDocDir = await getApplicationDocumentsDirectory(); + final copiedFile = await file.copy('${appDocDir.path}/${basename(file.path)}'); + return copiedFile.path.toString(); } /// Callback that is called after an image is picked whilst on the web platform. @@ -323,8 +373,12 @@ class HomePageState extends State { const apiURL = 'https://imgup.fly.dev/api/images'; final request = http.MultipartRequest('POST', Uri.parse(apiURL)); - final httpImage = http.MultipartFile.fromBytes('image', bytes, - contentType: MediaType.parse(lookupMimeType('', headerBytes: bytes)!), filename: platformFile.name,); + final httpImage = http.MultipartFile.fromBytes( + 'image', + bytes, + contentType: MediaType.parse(lookupMimeType('', headerBytes: bytes)!), + filename: platformFile.name, + ); request.files.add(httpImage); // Check the response and handle accordingly