Search
 
SCRIPT & CODE EXAMPLE
 

DART

show dialog close flutter

  BuildContext dialogContext; // <<----
  showDialog(
    context: context, // <<----
    barrierDismissible: false,
    builder: (BuildContext context) {
      dialogContext = context;
      return Dialog(
        child: new Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            new CircularProgressIndicator(),
            new Text("Loading"),
          ],
        ),
      );
    },
  );

  await _longOperation();
  Navigator.pop(dialogContext); // <<----
Comment

show dialog box on pressed flutter

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(title: Text("Testing")),
    body: Center(
      child: RaisedButton(
        child: Text("Show dialog"),
        onPressed: () {
          showDialog(
            context: context,
            builder: (context) {
              return Dialog(
                shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)),
                elevation: 16,
                child: Container(
                  height: 400.0,
                  width: 360.0,
                  child: ListView(
                    children: <Widget>[
                      SizedBox(height: 20),
                      Center(
                        child: Text(
                          "Leaderboard",
                          style: TextStyle(fontSize: 24, color: Colors.blue, fontWeight: FontWeight.bold),
                        ),
                      ),
                      SizedBox(height: 20),
                      _buildName(imageAsset: 'assets/chocolate.jpg', name: "Name 1", score: 1000),
                      _buildName(imageAsset: 'assets/chocolate.jpg', name: "Name 2", score: 2000),
                      _buildName(imageAsset: 'assets/chocolate.jpg', name: "Name 3", score: 3000),
                      _buildName(imageAsset: 'assets/chocolate.jpg', name: "Name 4", score: 4000),
                      _buildName(imageAsset: 'assets/chocolate.jpg', name: "Name 5", score: 5000),
                      _buildName(imageAsset: 'assets/chocolate.jpg', name: "Name 6", score: 6000),
                    ],
                  ),
                ),
              );
            },
          );
        },
      ),
    ),
  );
}

Widget _buildName({String imageAsset, String name, double score}) {
  return Padding(
    padding: const EdgeInsets.symmetric(horizontal: 20.0),
    child: Column(
      children: <Widget>[
        SizedBox(height: 12),
        Container(height: 2, color: Colors.redAccent),
        SizedBox(height: 12),
        Row(
          children: <Widget>[
            CircleAvatar(
              backgroundImage: AssetImage(imageAsset),
              radius: 30,
            ),
            SizedBox(width: 12),
            Text(name),
            Spacer(),
            Container(
              padding: EdgeInsets.symmetric(vertical: 8, horizontal: 20),
              child: Text("${score}"),
              decoration: BoxDecoration(
                color: Colors.yellow[900],
                borderRadius: BorderRadius.circular(20),
              ),
            ),
          ],
        ),
      ],
    ),
  );
}
Comment

flutter show dialog on start

  import 'dart:async';
  import 'package:flutter/material.dart';

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

  class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
          title: 'Trial',
          home: Scaffold(
              appBar: AppBar(title: Text('List scroll')), body: new MyHome()));
    }
  }

  class MyHome extends StatelessWidget { // Wrapper Widget
    @override
    Widget build(BuildContext context) {
      Future.delayed(Duration.zero, () => showAlert(context));
      return Container(
        child: Text("Hello world"),
      );
    }

    void showAlert(BuildContext context) {
      showDialog(
          context: context,
          builder: (context) => AlertDialog(
                content: Text("hi"),
              ));
    }
  }
Comment

how to display a dialog after build in flutter

class XxxxxWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
// [NG]We want to show dialog on Container widget.

 Future.delayed(Duration.zero, () => showMyDialog(context)); // import 'dart:async';
 return Container(
  child: FlatButton(.... //same as question
Comment

PREVIOUS NEXT
Code Example
Dart :: create extention in dart 
Dart :: Which one is performance wise better Text or extracted TextWidget function 
Dart :: dart compiler 
Dart :: how to create camera icon in flutter dev 
Dart :: tabbar flutter change background color 
Dart :: how to check if val only spaces in dart 
Dart :: flutter: unhandled element defs; Picture key: AssetBundlePictureKey 
Dart :: flutter dart imports 
Dart :: flutter sliver app bar remove top padding 
Dart :: a function body must be provided. try adding a function body. flutter 
Dart :: dart is operator 
Dart :: accumulator code example in flutter 
Dart :: rouned floating action button flutter 
Swift :: add shadow to collection view cell swift 
Swift :: swift change button text 
Swift :: how to replace certain characters in string swift 
Swift :: how to disable uitableview selection in swift 
Swift :: Change BackgroundColor of Picker ios swift 
Swift :: check when webview finish loading swift 
Swift :: swift do catch 
Swift :: get index filter swift 
Swift :: add top corner radius swift 
Swift :: swift collection view check if you are at the bottom 
Swift :: swift go to root view controller 
Swift :: swift navigation bar title color 
Swift :: iOS & Swift - The Complete iOS App Development Bootcamp 
Swift :: swift dictionary get key from valye 
Swift :: if else if and else statments in swift language 
Swift :: type String and int swift addition 
Swift :: Swift for-in Loop 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =