Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Flutter Tokyo Meetup #9 で発表したときのサンプルコード
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatelessWidget {
final String title;
const MyHomePage({this.title});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(title)),
body: Center(
child: RaisedButton(
child: Text('リッチなポップアップ'),
onPressed: () {
_showRichPopup(context);
},
),
),
);
}
void _showRichPopup(BuildContext context) {
showGeneralDialog(
context: context,
barrierLabel: 'Dismiss',
barrierColor: Colors.black.withOpacity(0.5),
barrierDismissible: false,
transitionDuration: const Duration(milliseconds: 200),
transitionBuilder: (_, animation, __, child) {
return ScaleTransition(
alignment: Alignment.center,
scale: animation,
child: child,
);
},
pageBuilder: (context, _, __) {
final size = MediaQuery.of(context).size;
return Center(
child: SizedBox(
height: size.height * 0.7,
width: size.width * 0.8,
child: Card(
elevation: 8,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(12),
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Icon(
Icons.image,
size: 200,
),
Text(
'Rich Popup Screen 😁',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.black,
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Text(
'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ',
textAlign: TextAlign.left,
maxLines: 5,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.grey,
fontSize: 18,
),
),
),
FlatButton(
onPressed: () {
Navigator.pop(context);
},
color: Colors.blue,
shape: StadiumBorder(),
child: Text(
'OK',
style: TextStyle(color: Colors.white),
),
)
],
),
),
),
);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment