Skip to content

Instantly share code, notes, and snippets.

@abarth
Last active November 30, 2016 00:09
Show Gist options
  • Save abarth/f6b1dbaf2d78bdead6bcaf71c8c97276 to your computer and use it in GitHub Desktop.
Save abarth/f6b1dbaf2d78bdead6bcaf71c8c97276 to your computer and use it in GitHub Desktop.
road-services.dart
import 'dart:math' as math;
import 'package:flutter/material.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Road Services',
theme: new ThemeData(
primarySwatch: Colors.green,
),
home: new MyHomePage(title: 'Road Services'),
);
}
}
class MyDrawerHeader extends StatefulWidget {
const MyDrawerHeader({ Key key }) : super(key: key);
@override
_MyDrawerHeaderState createState() => new _MyDrawerHeaderState();
}
class _MyDrawerHeaderState extends State<MyDrawerHeader> {
bool _logoHasName = true;
bool _logoHorizontal = true;
Map<int, Color> _swatch = Colors.blue;
@override
Widget build(BuildContext context) {
final double systemTopPadding = MediaQuery.of(context).padding.top;
return new DrawerHeader(
decoration: new FlutterLogoDecoration(
margin: new EdgeInsets.fromLTRB(12.0, 12.0 + systemTopPadding, 12.0, 12.0),
style: _logoHasName ? _logoHorizontal ? FlutterLogoStyle.horizontal
: FlutterLogoStyle.stacked
: FlutterLogoStyle.markOnly,
swatch: _swatch,
textColor: const Color(0xFF616161),
),
duration: const Duration(milliseconds: 750),
child: new GestureDetector(
onLongPress: () {
setState(() {
_logoHorizontal = !_logoHorizontal;
if (!_logoHasName)
_logoHasName = true;
});
},
onTap: () {
setState(() {
_logoHasName = !_logoHasName;
});
},
onDoubleTap: () {
setState(() {
final List<Map<int, Color>> options = <Map<int, Color>>[];
if (_swatch != Colors.blue)
options.addAll(<Map<int, Color>>[Colors.blue, Colors.blue, Colors.blue, Colors.blue, Colors.blue, Colors.blue, Colors.blue]);
if (_swatch != Colors.amber)
options.addAll(<Map<int, Color>>[Colors.amber, Colors.amber, Colors.amber]);
if (_swatch != Colors.red)
options.addAll(<Map<int, Color>>[Colors.red, Colors.red, Colors.red]);
if (_swatch != Colors.indigo)
options.addAll(<Map<int, Color>>[Colors.indigo, Colors.indigo, Colors.indigo]);
if (_swatch != Colors.pink)
options.addAll(<Map<int, Color>>[Colors.pink]);
if (_swatch != Colors.purple)
options.addAll(<Map<int, Color>>[Colors.purple]);
if (_swatch != Colors.cyan)
options.addAll(<Map<int, Color>>[Colors.cyan]);
_swatch = options[new math.Random().nextInt(options.length)];
});
}
)
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool _switch1 = true;
bool _switch2 = false;
double _slider = 0.2;
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(config.title),
),
drawer: new Drawer(
child: new Block(
children: <Widget>[
new MyDrawerHeader(),
new AboutDrawerItem(),
],
),
),
body: new Padding(
padding: new EdgeInsets.all(16.0),
child: new Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Expanded(
child: new Card(
child: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new ListItem(
leading: new Icon(Icons.local_gas_station),
title: new Text('Gas Station'),
onTap: () { },
),
new ListItem(
leading: new Icon(Icons.local_grocery_store),
title: new Text('Grocery Stores'),
onTap: () { },
),
new ListItem(
leading: new Icon(Icons.restaurant),
title: new Text('Restaurants'),
onTap: () { },
),
new ListItem(
leading: new Icon(Icons.store_mall_directory),
title: new Text('Stores'),
onTap: () { },
),
new ListItem(
leading: new Icon(Icons.build),
title: new Text('Car mechanics'),
onTap: () { },
),
],
),
),
),
new Expanded(
child: new Column(
children: <Widget>[
new Card(
child: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new ListItem(
leading: new Icon(Icons.traffic),
title: new Text('Traffic Lights'),
trailing: new Switch(
value: _switch1,
onChanged: (bool value) { setState(() { _switch1 = value; }); },
),
onTap: () { setState(() { _switch1 = !_switch1; }); },
),
new ListItem(
leading: new Icon(Icons.local_car_wash),
title: new Text('Car Wash'),
trailing: new Switch(
value: _switch2,
onChanged: (bool value) { setState(() { _switch2 = value; }); },
),
onTap: () { setState(() { _switch2 = !_switch2; }); },
),
],
),
),
new Card(
child: new Padding(
padding: new EdgeInsets.all(12.0),
child: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new Text('Price Multiplier'),
new Slider(
value: _slider,
onChanged: (double value) { setState(() { _slider = value; }); },
),
new Padding(
padding: new EdgeInsets.all(8.0),
child: new Center(
child: new RaisedButton(
color: Theme.of(context).primaryColor,
colorBrightness: Theme.of(context).primaryColorBrightness,
onPressed: () { },
child: new Text('DISTRIBUTE GIFTS'),
),
),
),
],
),
),
),
],
),
),
],
),
),
floatingActionButton: new FloatingActionButton(
onPressed: () { },
child: new Icon(Icons.share),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment