Unverified Commit 4f9b19e2 authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

fix for upcoming use_build_context_synchronously changes (#111539)

parent 6b1f84fe
...@@ -41,7 +41,7 @@ class ComponentDemoTabData { ...@@ -41,7 +41,7 @@ class ComponentDemoTabData {
int get hashCode => Object.hash(tabName, description, documentationUrl); int get hashCode => Object.hash(tabName, description, documentationUrl);
} }
class TabbedComponentDemoScaffold extends StatelessWidget { class TabbedComponentDemoScaffold extends StatefulWidget {
const TabbedComponentDemoScaffold({ const TabbedComponentDemoScaffold({
super.key, super.key,
this.title, this.title,
...@@ -57,8 +57,13 @@ class TabbedComponentDemoScaffold extends StatelessWidget { ...@@ -57,8 +57,13 @@ class TabbedComponentDemoScaffold extends StatelessWidget {
final bool isScrollable; final bool isScrollable;
final bool showExampleCodeAction; final bool showExampleCodeAction;
@override
State<TabbedComponentDemoScaffold> createState() => _TabbedComponentDemoScaffoldState();
}
class _TabbedComponentDemoScaffoldState extends State<TabbedComponentDemoScaffold> {
void _showExampleCode(BuildContext context) { void _showExampleCode(BuildContext context) {
final String? tag = demos![DefaultTabController.of(context)!.index].exampleCodeTag; final String? tag = widget.demos![DefaultTabController.of(context)!.index].exampleCodeTag;
if (tag != null) { if (tag != null) {
Navigator.push(context, MaterialPageRoute<FullScreenCodeDialog>( Navigator.push(context, MaterialPageRoute<FullScreenCodeDialog>(
builder: (BuildContext context) => FullScreenCodeDialog(exampleCodeTag: tag) builder: (BuildContext context) => FullScreenCodeDialog(exampleCodeTag: tag)
...@@ -67,7 +72,7 @@ class TabbedComponentDemoScaffold extends StatelessWidget { ...@@ -67,7 +72,7 @@ class TabbedComponentDemoScaffold extends StatelessWidget {
} }
Future<void> _showApiDocumentation(BuildContext context) async { Future<void> _showApiDocumentation(BuildContext context) async {
final String? url = demos![DefaultTabController.of(context)!.index].documentationUrl; final String? url = widget.demos![DefaultTabController.of(context)!.index].documentationUrl;
if (url == null) { if (url == null) {
return; return;
} }
...@@ -75,7 +80,7 @@ class TabbedComponentDemoScaffold extends StatelessWidget { ...@@ -75,7 +80,7 @@ class TabbedComponentDemoScaffold extends StatelessWidget {
final Uri uri = Uri.parse(url); final Uri uri = Uri.parse(url);
if (await canLaunchUrl(uri)) { if (await canLaunchUrl(uri)) {
await launchUrl(uri); await launchUrl(uri);
} else { } else if (mounted) {
showDialog<void>( showDialog<void>(
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
...@@ -96,12 +101,12 @@ class TabbedComponentDemoScaffold extends StatelessWidget { ...@@ -96,12 +101,12 @@ class TabbedComponentDemoScaffold extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return DefaultTabController( return DefaultTabController(
length: demos!.length, length: widget.demos!.length,
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text(title!), title: Text(widget.title!),
actions: <Widget>[ actions: <Widget>[
...?actions, ...?widget.actions,
Builder( Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
return IconButton( return IconButton(
...@@ -110,7 +115,7 @@ class TabbedComponentDemoScaffold extends StatelessWidget { ...@@ -110,7 +115,7 @@ class TabbedComponentDemoScaffold extends StatelessWidget {
); );
}, },
), ),
if (showExampleCodeAction) if (widget.showExampleCodeAction)
Builder( Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
return IconButton( return IconButton(
...@@ -122,12 +127,12 @@ class TabbedComponentDemoScaffold extends StatelessWidget { ...@@ -122,12 +127,12 @@ class TabbedComponentDemoScaffold extends StatelessWidget {
), ),
], ],
bottom: TabBar( bottom: TabBar(
isScrollable: isScrollable, isScrollable: widget.isScrollable,
tabs: demos!.map<Widget>((ComponentDemoTabData data) => Tab(text: data.tabName)).toList(), tabs: widget.demos!.map<Widget>((ComponentDemoTabData data) => Tab(text: data.tabName)).toList(),
), ),
), ),
body: TabBarView( body: TabBarView(
children: demos!.map<Widget>((ComponentDemoTabData demo) { children: widget.demos!.map<Widget>((ComponentDemoTabData demo) {
return SafeArea( return SafeArea(
top: false, top: false,
bottom: false, bottom: false,
......
...@@ -35,9 +35,11 @@ class UpdaterState extends State<Updater> { ...@@ -35,9 +35,11 @@ class UpdaterState extends State<Updater> {
_lastUpdateCheck = DateTime.now(); _lastUpdateCheck = DateTime.now();
final String? updateUrl = await widget.updateUrlFetcher(); final String? updateUrl = await widget.updateUrlFetcher();
final bool? wantsUpdate = await showDialog<bool>(context: context, builder: _buildDialog); if (mounted) {
if (wantsUpdate != null && updateUrl != null && wantsUpdate) { final bool? wantsUpdate = await showDialog<bool>(context: context, builder: _buildDialog);
launchUrl(Uri.parse(updateUrl)); if (wantsUpdate != null && updateUrl != null && wantsUpdate) {
launchUrl(Uri.parse(updateUrl));
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment