Skip to content

Instantly share code, notes, and snippets.

@ubershmekel
Last active September 28, 2023 03:00
Show Gist options
  • Save ubershmekel/13a957766549a2082c20cfb3919f90b1 to your computer and use it in GitHub Desktop.
Save ubershmekel/13a957766549a2082c20cfb3919f90b1 to your computer and use it in GitHub Desktop.
Test a stackoverflow solution. It doesn't work
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
import 'dart:ui';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
double _paddingScaleFactor(double textScaleFactor) {
final double clampedTextScaleFactor = clampDouble(textScaleFactor, 1.0, 2.0);
// The final padding scale factor is clamped between 1/3 and 1. For example,
// a non-scaled padding of 24 will produce a padding between 24 and 8.
return lerpDouble(1.0, 1.0 / 3.0, clampedTextScaleFactor - 1.0)!;
}
class MyHomePage extends StatefulWidget {
final String title;
const MyHomePage({
Key? key,
required this.title,
}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
final size = MediaQuery.sizeOf(context);
final double paddingScaleFactor =
_paddingScaleFactor(MediaQuery.textScaleFactorOf(context));
final EdgeInsets effectivePadding = MediaQuery.viewInsetsOf(context) +
EdgeInsets.symmetric(
horizontal: 40 *
paddingScaleFactor, // inset padding of dialog, left and right (20 + 20)
);
final maxWidth = size.width - // width of screen
effectivePadding.left - // left padding of dialog
effectivePadding.right - // right padding of dialog
24 * 2 * paddingScaleFactor - // left and right padding of button
48; // width of icon
setState(() {
_counter++;
});
showDialog(
context: context,
builder: (BuildContext context) => AlertDialog(
// title: const Text('Popup example'),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(children: [
Expanded(
child: FloatingActionButton.extended(
heroTag: UniqueKey(),
icon: const Icon(Icons.nordic_walking),
label: const Text(
'j laskdjfla sdlf alsdk flakj flkasj dlk jalsd asdf asdlf asldkj fal ads aa da s ',
),
onPressed: () {},
))
]),
const SizedBox(height: 20),
Row(children: [
Expanded(
child: SizedBox(
height: 80,
child: FloatingActionButton.extended(
heroTag: UniqueKey(),
icon: const Icon(Icons.nordic_walking),
label: ConstrainedBox(
constraints: BoxConstraints(
maxWidth: maxWidth,
),
child: const Row(
children: [
Expanded(
child: Text(
'asdfasdjlfk asdk jfla sdflak sdfla df.a sdf askd.jf .aksd ak jf.a ksjdja .kja. jad.k j sda jflaksd jlas jdlfka sdlkfja lskdfjlak sdjlfkj asldkf jalskjflkjasd lkj faljd lasjlk jdlkaj s',
),
),
],
),
),
onPressed: () {},
)))
]),
],
),
));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment