Skip to content

Instantly share code, notes, and snippets.

@natintosh
Created March 7, 2020 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natintosh/d21db67b21d7e5ce1f0eba2ad99b9218 to your computer and use it in GitHub Desktop.
Save natintosh/d21db67b21d7e5ce1f0eba2ad99b9218 to your computer and use it in GitHub Desktop.
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
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(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Container(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: <Widget>[
MyCard(color: Colors.red),
MyCard(color: Colors.blue),
MyCard(color: Colors.green),
MyCard(color: Colors.orange),
MyCard(color: Colors.lime),
MyCard(color: Colors.yellow),
MyCard(color: Colors.black),
MyCard(color: Colors.amber),
MyCard(color: Colors.brown),
MyCard(color: Colors.indigo),
MyCard(color: Colors.grey),
MyCard(color: Colors.white),
MyCard(color: Colors.purple),
MyCard(color: Colors.teal),
],
),
),
),
),
);
}
}
class MyCard extends StatelessWidget {
final Color color;
const MyCard({Key key, this.color}) : super(key: key);
@override
Widget build(BuildContext context) {
return Card(
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
18.0,
),
),
child: GestureDetector(
onTap: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Color'),
content: Text(color.toString()),
actions: <Widget>[
RaisedButton(
child: Text('CLOSE'),
onPressed: () {
Navigator.pop(context);
})
]);
});
},
child: Container(
color: color,
height: MediaQuery.of(context).size.height * 0.35,
width: MediaQuery.of(context).size.width * 0.25,
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment