From 1508b0ffddbb9b19b396a1cb2715bfbbd0f642f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Alejandro=20Casta=C3=B1o=20Arcila?= Date: Tue, 12 May 2026 22:14:08 -0500 Subject: [PATCH 1/4] perf: extract non-const style objects to static const fields in aiml_groq_ex.dart --- lib/routes/aiml_groq_ex.dart | 54 ++++++++++++++++++++++++------------ pubspec.lock | 8 +++--- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/lib/routes/aiml_groq_ex.dart b/lib/routes/aiml_groq_ex.dart index 83ab097..e0166cd 100644 --- a/lib/routes/aiml_groq_ex.dart +++ b/lib/routes/aiml_groq_ex.dart @@ -225,6 +225,39 @@ class MyMessageBubbleTile extends StatelessWidget { required this.isMe, }); + static const _kMeMargin = EdgeInsets.only( + top: 8.0, + bottom: 8.0, + left: 80.0, + ); + static const _kOtherMargin = EdgeInsets.only( + top: 8.0, + bottom: 8.0, + right: 80.0, + ); + static const _kPadding = EdgeInsets.symmetric( + horizontal: 15.0, + vertical: 10.0, + ); + static const _kMeRadius = BorderRadius.only( + topLeft: Radius.circular(15.0), + bottomLeft: Radius.circular(15.0), + bottomRight: Radius.circular(15.0), + ); + static const _kOtherRadius = BorderRadius.only( + topRight: Radius.circular(15.0), + bottomLeft: Radius.circular(15.0), + bottomRight: Radius.circular(15.0), + ); + static const _kMeDecoration = BoxDecoration( + color: Color(0xFFE0E0E0), + borderRadius: _kMeRadius, + ); + static const _kOtherDecoration = BoxDecoration( + color: Color(0xFFBBDEFB), + borderRadius: _kOtherRadius, + ); + final String message; final bool isMe; @@ -240,24 +273,9 @@ class MyMessageBubbleTile extends StatelessWidget { final msgBubble = Align( alignment: isMe ? Alignment.centerRight : Alignment.centerLeft, child: Container( - margin: isMe - ? EdgeInsets.only(top: 8.0, bottom: 8.0, left: 80.0) - : EdgeInsets.only(top: 8.0, bottom: 8.0, right: 80), - padding: EdgeInsets.symmetric(horizontal: 15.0, vertical: 10.0), - decoration: BoxDecoration( - color: isMe ? Colors.grey[300] : Colors.blue[100], - borderRadius: isMe - ? BorderRadius.only( - topLeft: Radius.circular(15.0), - bottomLeft: Radius.circular(15.0), - bottomRight: Radius.circular(15.0), - ) - : BorderRadius.only( - topRight: Radius.circular(15.0), - bottomLeft: Radius.circular(15.0), - bottomRight: Radius.circular(15.0), - ), - ), + margin: isMe ? _kMeMargin : _kOtherMargin, + padding: _kPadding, + decoration: isMe ? _kMeDecoration : _kOtherDecoration, child: MarkdownBody(data: message, selectable: true), ), ); diff --git a/pubspec.lock b/pubspec.lock index b0d0787..8f935ab 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1648,10 +1648,10 @@ packages: dependency: transitive description: name: matcher - sha256: "12956d0ad8390bbcc63ca2e1469c0619946ccb52809807067a7020d57e647aa6" + sha256: dc0b7dc7651697ea4ff3e69ef44b0407ea32c487a39fff6a4004fa585e901861 url: "https://pub.dev" source: hosted - version: "0.12.18" + version: "0.12.19" material_color_utilities: dependency: transitive description: @@ -2221,10 +2221,10 @@ packages: dependency: transitive description: name: test_api - sha256: "93167629bfc610f71560ab9312acdda4959de4df6fac7492c89ff0d3886f6636" + sha256: "8161c84903fd860b26bfdefb7963b3f0b68fee7adea0f59ef805ecca346f0c7a" url: "https://pub.dev" source: hosted - version: "0.7.9" + version: "0.7.10" timelines_plus: dependency: "direct main" description: From dfb72e3e8ed41cd55101cd42ec186d8a0d4d784a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Alejandro=20Casta=C3=B1o=20Arcila?= Date: Tue, 12 May 2026 22:36:23 -0500 Subject: [PATCH 2/4] perf: add RepaintBoundary around IndexedStack children for tab isolation --- lib/home_page.dart | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/home_page.dart b/lib/home_page.dart index dc29708..b38245e 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -121,12 +121,26 @@ class _MyHomePageState extends ConsumerState { body: IndexedStack( index: ref.watch(mySettingsProvider).currentTabIdx, children: [ - ListView(controller: _scrollController1, children: basicDemos), - ListView(controller: _scrollController2, children: advancedDemos), - ListView(controller: _scrollController3, children: inactionDemos), - ListView( - controller: _scrollController4, - children: bookmarkAndAboutDemos, + RepaintBoundary( + child: ListView(controller: _scrollController1, children: basicDemos), + ), + RepaintBoundary( + child: ListView( + controller: _scrollController2, + children: advancedDemos, + ), + ), + RepaintBoundary( + child: ListView( + controller: _scrollController3, + children: inactionDemos, + ), + ), + RepaintBoundary( + child: ListView( + controller: _scrollController4, + children: bookmarkAndAboutDemos, + ), ), ], ), From aad285043a83addc6eb282a41b10370ef4dcd4c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Alejandro=20Casta=C3=B1o=20Arcila?= Date: Tue, 12 May 2026 22:50:16 -0500 Subject: [PATCH 3/4] perf: replace broad setState() with ValueNotifier in networking_rest_api_fetch_ex.dart --- lib/routes/networking_rest_api_fetch_ex.dart | 70 ++++++++++++-------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/lib/routes/networking_rest_api_fetch_ex.dart b/lib/routes/networking_rest_api_fetch_ex.dart index 45724f2..483203b 100644 --- a/lib/routes/networking_rest_api_fetch_ex.dart +++ b/lib/routes/networking_rest_api_fetch_ex.dart @@ -15,9 +15,9 @@ class RestApiFetchExample extends StatefulWidget { class _RestApiFetchExampleState extends State { late TextEditingController _urlController; late TextEditingController _apiTokenController; - String _responseBody = ''; - String _error = ''; - bool _pending = false; + final _responseBody = ValueNotifier(''); + final _error = ValueNotifier(''); + final _pending = ValueNotifier(false); @override void initState() { @@ -27,6 +27,16 @@ class _RestApiFetchExampleState extends State { ..text = 'https://jsonplaceholder.typicode.com/posts/1'; } + @override + void dispose() { + _urlController.dispose(); + _apiTokenController.dispose(); + _responseBody.dispose(); + _error.dispose(); + _pending.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { return ListView( @@ -49,41 +59,49 @@ class _RestApiFetchExampleState extends State { ), OverflowBar( children: [ - ElevatedButton( - onPressed: _pending - ? null - : () => this._httpGet( - _urlController.text, - _apiTokenController.text, - ), - child: const Text('Get'), + ValueListenableBuilder( + valueListenable: _pending, + builder: (context, pending, _) => ElevatedButton( + onPressed: pending + ? null + : () => this._httpGet( + _urlController.text, + _apiTokenController.text, + ), + child: const Text('Get'), + ), ), ElevatedButton(onPressed: this._reset, child: const Text('Reset')), ], ), - Text('Response body=$_responseBody'), + ValueListenableBuilder( + valueListenable: _responseBody, + builder: (context, responseBody, _) => Text( + 'Response body=$responseBody', + ), + ), const Divider(), - Text('Error=$_error'), + ValueListenableBuilder( + valueListenable: _error, + builder: (context, error, _) => Text('Error=$error'), + ), ], ); } void _reset({bool resetControllers = true}) { - setState(() { - if (resetControllers) { - this._urlController.text = - 'https://jsonplaceholder.typicode.com/posts/1'; - } - this._responseBody = ''; - this._error = ''; - this._pending = false; - }); + if (resetControllers) { + this._urlController.text = 'https://jsonplaceholder.typicode.com/posts/1'; + } + _responseBody.value = ''; + _error.value = ''; + _pending.value = false; } // Using the http package we can easily GET data from REST APIs. Future _httpGet(String url, String apiToken) async { _reset(); - setState(() => this._pending = true); + _pending.value = true; try { final http.Response response = await http.get( Uri.parse(url), @@ -95,10 +113,10 @@ class _RestApiFetchExampleState extends State { // heavy json parsing work in a background isolate. final parsed = await compute(jsonDecode, response.body); print('parsed json object=$parsed'); - setState(() => this._responseBody = response.body); + _responseBody.value = response.body; } catch (e) { - setState(() => this._error = e.toString()); + _error.value = e.toString(); } - setState(() => this._pending = false); + _pending.value = false; } } From b156a0a6aae2c6d8ac2defef479196be362d8939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Alejandro=20Casta=C3=B1o=20Arcila?= Date: Sat, 23 May 2026 20:50:43 -0500 Subject: [PATCH 4/4] fix: add missing cupertino import for CupertinoPageTransitionsBuilder --- lib/themes.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/themes.dart b/lib/themes.dart index d8239eb..c1b3ed9 100644 --- a/lib/themes.dart +++ b/lib/themes.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter/cupertino.dart'; // This file is adapted from // https://github.com/flutter/flutter/blob/master/examples/flutter_gallery/lib/gallery/themes.dart