0

I want to create a dialog bottom sheet like below image gif. Button is from first screen when show dialog button is still clickable.

enter image description here

My Result

enter image description here

phearun
  • 13
  • 6
  • Your answer is here please check with this once https://stackoverflow.com/questions/50376200/how-to-create-a-modal-bottomsheet-with-circular-corners-in-flutter – SSVernekar Nov 23 '20 at 06:54
  • @SSVernekar dialog will overlay my button payment. when open showModalBottomSheet. – phearun Nov 23 '20 at 10:22

2 Answers2

0

for more information about the bottom sheet please check the documentaton

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: RaisedButton(
          onPressed: () {
            _settingModalBottomSheet();
          },
          child: Text('Show Bottom Sheet'),
        ),
      ),
    );
  }

  void _settingModalBottomSheet() {
    showModalBottomSheet(
      context: context,
      builder: (BuildContext bc) {
        return Container(
          child: Wrap(
            children: <Widget>[
              ListTile(
                  leading: Icon(Icons.music_note),
                  title: Text('Music'),
                  onTap: () => {}),
              ListTile(
                leading: Icon(Icons.videocam),
                title: Text('Video'),
                onTap: () => {},
              ),
            ],
          ),
        );
      },
    );
  }
}
Mr Random
  • 1,992
  • 7
  • 20
  • maybe you don't understand my purpose. I need button in the Bottom Position and then open dialog with that button without overlay my button. – phearun Nov 23 '20 at 10:17
0

You can get this in 3 ways(first 2 ways will hide payment section as you needed)

`Case 1 - Use the global key

import 'package:flutter/material.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  runApp(MaterialApp(
    home: BottomWidget(),
  ));
}

class BottomWidget extends StatelessWidget {
  final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
  void showOrdersModel(BuildContext context) {
    scaffoldKey.currentState.showBottomSheet((context) {
      return Container(
        height: 250, // change height as required
        decoration: BoxDecoration(
          color: Colors.white,
          boxShadow: [
            BoxShadow(
              blurRadius: 10,
              color: Colors.grey[300],
              spreadRadius: 5,
            ),
          ],
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(12),
            topRight: Radius.circular(12),
          ),
        ),
        child: Center(child: Text('Orders')),
      );
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: scaffoldKey,
      body: Center(
        child: RaisedButton(
          onPressed: () => showOrdersModel(context), // pass context to work
          child: Text('Show my orders'),
        ),
      ),
    );
  }
}

Case 2 - Use scaffold Note: You need Scaffold widget

import 'package:flutter/material.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  runApp(MaterialApp(
    home: BottomWidget(),
  ));
}

class BottomWidget extends StatefulWidget {
  @override
  _BottomWidgetState createState() => _BottomWidgetState();
}

class _BottomWidgetState extends State<BottomWidget> {
  void showOrdersModel(BuildContext context) {
    Scaffold.of(context).showBottomSheet((context) {
      return Container(
        height: 250, // change height as required
        decoration: BoxDecoration(
          color: Colors.white,
          boxShadow: [
            BoxShadow(
              blurRadius: 10,
              color: Colors.grey[300],
              spreadRadius: 5,
            ),
          ],
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(12),
            topRight: Radius.circular(12),
          ),
        ),
        child: Center(child: Text('Orders')),
      );
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Builder(
        builder: (ctx) => Center(
          child: RaisedButton(
            onPressed: () => showOrdersModel(ctx), // pass context to work
            child: Text('Show my orders'),
          ),
        ),
      ),
    );
  }
}

Case 3 - Use showModalBottomSheet from the flutter

import 'package:flutter/material.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  runApp(MaterialApp(
    home: BottomWidget(),
  ));
}

class BottomWidget extends StatelessWidget {
  void showOrdersModel(BuildContext context) {
    showModalBottomSheet(
      context: context,
      shape: RoundedRectangleBorder( // apply this to get the rounder corners
        borderRadius: BorderRadius.vertical(
          top: Radius.circular(20),
        ),
      ),
      clipBehavior: Clip.antiAliasWithSaveLayer,
      builder: (ctx) {
        return Container(
          height: 250, // change height as required
          color: Colors.transparent,
          child: Center(child: Text('Orders')),
        );
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: RaisedButton(
          onPressed: () => showOrdersModel(context), // pass context to work
          child: Text('Show my orders'),
        ),
      ),
    );
  }
}

Balaji Venkatraman
  • 1,228
  • 12
  • 19
  • But when I move button click to bottom when dialog is opened it's overlay my button. Do you have any idea about that? – phearun Nov 23 '20 at 14:10
  • sorry, I cannot attach my code it's too long .You can try by positioned the button on bottom and click open dialog you will see. – phearun Nov 26 '20 at 02:08