1

I'd like to add a modal bottom sheet to my app. I built the widget I want to display, however, the sheet animation is a bit too slow for me. I'd like to make it a bit faster. I didn't find anything about the animation speed, duration, so I'm not sure how to achieve a faster animation in Flutter's bottom sheet.

Edric
  • 24,639
  • 13
  • 81
  • 91
Vince Varga
  • 6,101
  • 6
  • 43
  • 60
  • 1
    its fixed, to 200 ms, see `material/bottom_sheet.dart` - the first line after imports: `const Duration _bottomSheetDuration = Duration(milliseconds: 200);` – pskink Jul 05 '19 at 10:08
  • I added an answer to a similar question [here](https://stackoverflow.com/a/66665412/13793197) – kohjakob Mar 17 '21 at 00:38

1 Answers1

3

You can configure showModalBottomSheet's transitionAnimationController using AnimationController to update its duration(expand) and reversDuration(retract). Here's a demo

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
  late AnimationController controller;
  @override
  initState() {
    super.initState();
    // Initialize AnimationController
    initController();
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }
  
  void initController(){
    controller = BottomSheet.createAnimationController(this);
    controller.duration = const Duration(milliseconds: 100);
    controller.reverseDuration = const Duration(milliseconds: 100);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: const Center(
        child: Text('Click button to show bottom sheet'),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => showModalBottomSheet(
            transitionAnimationController: controller,
            context: context,
            builder: (builder) {
              return const Center(
                child: Text("Bottom sheet"),
              );
            }).whenComplete(() => initController()), // Initialize AnimationController after the controller has been disposed
        tooltip: 'Bottom Sheet',
        child: const Icon(Icons.arrow_upward_sharp),
      ),
    );
  }
}

Demo

Omatt
  • 8,564
  • 2
  • 42
  • 144