Skip to content

Instantly share code, notes, and snippets.

@slightfoot
Last active July 30, 2025 18:01
Show Gist options
  • Select an option

  • Save slightfoot/a69a98ec1727877caafb1b3ba1582f27 to your computer and use it in GitHub Desktop.

Select an option

Save slightfoot/a69a98ec1727877caafb1b3ba1582f27 to your computer and use it in GitHub Desktop.

Revisions

  1. slightfoot revised this gist Jul 30, 2025. 1 changed file with 31 additions and 33 deletions.
    64 changes: 31 additions & 33 deletions humpday_2025-07-30_1.dart
    Original file line number Diff line number Diff line change
    @@ -57,7 +57,7 @@ class Home extends StatelessWidget {
    context: context,
    enableDrag: false,
    isScrollControlled: true,
    builder:(_) => const FormInputBottomSheet(count: 10),
    builder: (_) => const FormInputBottomSheet(count: 10),
    );
    },
    child: const Text('Show Sheet'),
    @@ -77,48 +77,46 @@ class FormInputBottomSheet extends StatelessWidget {

    @override
    Widget build(BuildContext context) {
    final rootViewPadding = MediaQueryData.fromView(View.of(context)).viewPadding;
    final viewInsets = MediaQuery.viewInsetsOf(context);
    return ViewInsetsPadding(
    child: ConstrainedBox(
    constraints: BoxConstraints(
    maxHeight: MediaQuery.sizeOf(context).height * 0.7,
    ),
    child: IntrinsicHeight(
    child: Column(
    crossAxisAlignment: CrossAxisAlignment.stretch,
    children: [
    Expanded(
    child: SingleChildScrollView(
    child: Padding(
    padding: const EdgeInsets.symmetric(
    vertical: 16.0,
    horizontal: 24.0,
    child: SingleChildScrollView(
    padding: EdgeInsets.only(
    top: viewInsets.bottom > 0.0 ? rootViewPadding.top : 0.0,
    ),
    child: Padding(
    padding: const EdgeInsets.symmetric(
    vertical: 16.0,
    horizontal: 24.0,
    ),
    child: Column(
    crossAxisAlignment: CrossAxisAlignment.stretch,
    spacing: 16.0,
    children: [
    for (int i = 0; i < count; i++) //
    //
    TextFormField(
    decoration: InputDecoration(
    labelText: 'Field $i',
    ),
    ),
    child: Column(
    crossAxisAlignment: CrossAxisAlignment.stretch,
    spacing: 16.0,
    children: [
    for (int i = 0; i < count; i++) //
    //
    TextFormField(
    decoration: InputDecoration(
    labelText: 'Field $i',
    ),
    ),
    ],
    Padding(
    padding: const EdgeInsets.all(12.0),
    child: ElevatedButton(
    onPressed: () {
    Navigator.of(context).pop();
    },
    child: const Text('Submit'),
    ),
    ),
    ),
    ),
    Padding(
    padding: const EdgeInsets.all(12.0),
    child: ElevatedButton(
    onPressed: () {
    Navigator.of(context).pop();
    },
    child: const Text('Submit'),
    ),
    ],
    ),
    ],
    ),
    ),
    ),
    ),
  2. slightfoot revised this gist Jul 30, 2025. 1 changed file with 47 additions and 37 deletions.
    84 changes: 47 additions & 37 deletions humpday_2025-07-30_1.dart
    Original file line number Diff line number Diff line change
    @@ -56,7 +56,8 @@ class Home extends StatelessWidget {
    showModalBottomSheet(
    context: context,
    enableDrag: false,
    builder: FormInputBottomSheet.builder,
    isScrollControlled: true,
    builder:(_) => const FormInputBottomSheet(count: 10),
    );
    },
    child: const Text('Show Sheet'),
    @@ -67,50 +68,59 @@ class Home extends StatelessWidget {
    }

    class FormInputBottomSheet extends StatelessWidget {
    const FormInputBottomSheet({super.key});
    const FormInputBottomSheet({
    super.key,
    required this.count,
    });

    static Widget builder(BuildContext context) {
    return const FormInputBottomSheet();
    }
    final int count;

    @override
    Widget build(BuildContext context) {
    return ViewInsetsPadding(
    child: BottomSheet(
    enableDrag: false,
    onClosing: () {},
    builder: (context) {
    return SizedBox(
    height: 500.0,
    child: SingleChildScrollView(
    child: Padding(
    padding: const EdgeInsets.symmetric(
    vertical: 16.0,
    horizontal: 24.0,
    ),
    child: Column(
    crossAxisAlignment: CrossAxisAlignment.stretch,
    spacing: 16.0,
    children: [
    for (int i = 0; i < 10; i++) //
    //
    TextFormField(
    decoration: InputDecoration(
    labelText: 'Field $i',
    ),
    ),
    ElevatedButton(
    onPressed: () {
    Navigator.of(context).pop();
    },
    child: const Text('Submit'),
    child: ConstrainedBox(
    constraints: BoxConstraints(
    maxHeight: MediaQuery.sizeOf(context).height * 0.7,
    ),
    child: IntrinsicHeight(
    child: Column(
    crossAxisAlignment: CrossAxisAlignment.stretch,
    children: [
    Expanded(
    child: SingleChildScrollView(
    child: Padding(
    padding: const EdgeInsets.symmetric(
    vertical: 16.0,
    horizontal: 24.0,
    ),
    ],
    child: Column(
    crossAxisAlignment: CrossAxisAlignment.stretch,
    spacing: 16.0,
    children: [
    for (int i = 0; i < count; i++) //
    //
    TextFormField(
    decoration: InputDecoration(
    labelText: 'Field $i',
    ),
    ),
    ],
    ),
    ),
    ),
    ),
    Padding(
    padding: const EdgeInsets.all(12.0),
    child: ElevatedButton(
    onPressed: () {
    Navigator.of(context).pop();
    },
    child: const Text('Submit'),
    ),
    ),
    ),
    );
    },
    ],
    ),
    ),
    ),
    );
    }
  3. slightfoot revised this gist Jul 30, 2025. 1 changed file with 19 additions and 8 deletions.
    27 changes: 19 additions & 8 deletions humpday_2025-07-30_1.dart
    Original file line number Diff line number Diff line change
    @@ -75,14 +75,7 @@ class FormInputBottomSheet extends StatelessWidget {

    @override
    Widget build(BuildContext context) {
    return ChildBuilder(
    builder: (BuildContext context, Widget? child) {
    final viewInsets = MediaQuery.viewInsetsOf(context);
    return Padding(
    padding: EdgeInsets.only(bottom: viewInsets.bottom),
    child: child,
    );
    },
    return ViewInsetsPadding(
    child: BottomSheet(
    enableDrag: false,
    onClosing: () {},
    @@ -123,6 +116,24 @@ class FormInputBottomSheet extends StatelessWidget {
    }
    }

    class ViewInsetsPadding extends StatelessWidget {
    const ViewInsetsPadding({
    super.key,
    required this.child,
    });

    final Widget child;

    @override
    Widget build(BuildContext context) {
    final viewInsets = MediaQuery.viewInsetsOf(context);
    return Padding(
    padding: EdgeInsets.only(bottom: viewInsets.bottom),
    child: child,
    );
    }
    }

    class ChildBuilder extends StatelessWidget {
    const ChildBuilder({
    super.key,
  4. slightfoot created this gist Jul 30, 2025.
    138 changes: 138 additions & 0 deletions humpday_2025-07-30_1.dart
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,138 @@
    // MIT License
    //
    // Copyright (c) 2025 Simon Lightfoot
    //
    // Permission is hereby granted, free of charge, to any person obtaining a copy
    // of this software and associated documentation files (the "Software"), to deal
    // in the Software without restriction, including without limitation the rights
    // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    // copies of the Software, and to permit persons to whom the Software is
    // furnished to do so, subject to the following conditions:
    //
    // The above copyright notice and this permission notice shall be included in all
    // copies or substantial portions of the Software.
    //
    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    // SOFTWARE.
    //

    import 'package:flutter/material.dart';

    void main() {
    runApp(const App());
    }

    class App extends StatefulWidget {
    const App({super.key});

    @override
    State<App> createState() => _AppState();
    }

    class _AppState extends State<App> {
    @override
    Widget build(BuildContext context) {
    return const MaterialApp(
    debugShowCheckedModeBanner: false,
    home: Home(),
    );
    }
    }

    class Home extends StatelessWidget {
    const Home({super.key});

    @override
    Widget build(BuildContext context) {
    return Material(
    child: Center(
    child: ElevatedButton(
    onPressed: () {
    showModalBottomSheet(
    context: context,
    enableDrag: false,
    builder: FormInputBottomSheet.builder,
    );
    },
    child: const Text('Show Sheet'),
    ),
    ),
    );
    }
    }

    class FormInputBottomSheet extends StatelessWidget {
    const FormInputBottomSheet({super.key});

    static Widget builder(BuildContext context) {
    return const FormInputBottomSheet();
    }

    @override
    Widget build(BuildContext context) {
    return ChildBuilder(
    builder: (BuildContext context, Widget? child) {
    final viewInsets = MediaQuery.viewInsetsOf(context);
    return Padding(
    padding: EdgeInsets.only(bottom: viewInsets.bottom),
    child: child,
    );
    },
    child: BottomSheet(
    enableDrag: false,
    onClosing: () {},
    builder: (context) {
    return SizedBox(
    height: 500.0,
    child: SingleChildScrollView(
    child: Padding(
    padding: const EdgeInsets.symmetric(
    vertical: 16.0,
    horizontal: 24.0,
    ),
    child: Column(
    crossAxisAlignment: CrossAxisAlignment.stretch,
    spacing: 16.0,
    children: [
    for (int i = 0; i < 10; i++) //
    //
    TextFormField(
    decoration: InputDecoration(
    labelText: 'Field $i',
    ),
    ),
    ElevatedButton(
    onPressed: () {
    Navigator.of(context).pop();
    },
    child: const Text('Submit'),
    ),
    ],
    ),
    ),
    ),
    );
    },
    ),
    );
    }
    }

    class ChildBuilder extends StatelessWidget {
    const ChildBuilder({
    super.key,
    required this.builder,
    this.child,
    });

    final TransitionBuilder builder;
    final Widget? child;

    @override
    Widget build(BuildContext context) => builder(context, child);
    }