Skip to content

Instantly share code, notes, and snippets.

@av
Created October 10, 2019 14:06
Show Gist options
  • Save av/e63acad7ab64b882b27b8add4d293de9 to your computer and use it in GitHub Desktop.
Save av/e63acad7ab64b882b27b8add4d293de9 to your computer and use it in GitHub Desktop.
Flutter: tough_bikes first iteration
import 'dart:math';
import 'package:flutter/material.dart';
void main() => runApp(BikeApp());
class BikeApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
brightness: Brightness.dark,
primaryColor: Colors.black,
),
color: Colors.black,
home: Scaffold(
appBar: AppBar(
title: Title(
child: Text(
'Tough Bikes Inc.'.toUpperCase(),
style: TextStyle(
fontSize: 28.0,
fontWeight: FontWeight.w900,
letterSpacing: -2.0
),
),
color: Colors.white,
),
actions: <Widget>[
IconButton(
icon: Icon(Icons.menu),
onPressed: () {},
)
],
),
body: BikeList(),
),
);
}
}
class BikeList extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Expanded(
child: ListView(
physics: BouncingScrollPhysics(),
children: <Widget>[
BikeCard(bike: Bikes.hellrider),
BikeCard(bike: Bikes.desertRoamer),
BikeCard(bike: Bikes.lavaDozer),
BikeCard(bike: Bikes.swampEater),
BikeCard(bike: Bikes.dragonRoar),
],
),
),
Row(
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: BikeButton(),
),
)
],
),
],
);
}
}
class BikeButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return RaisedButton(
onPressed: () {},
child: Text('Buy Tough Bike'.toUpperCase()),
);
}
}
class BikeCard extends StatelessWidget {
final Bike bike;
BikeCard({this.bike});
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.all(16.0),
padding: const EdgeInsets.all(16.0),
decoration: BoxDecoration(
color: Colors.white10,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
CircleAvatar(),
Container(
width: 16.0,
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
bike.name,
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
Text(
bike.description,
softWrap: true,
),
Divider(
thickness: 2.0,
),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
MetricValue(
icon: Icons.remove_red_eye,
value: bike.views.toString(),
),
Container(width: 16.0),
MetricValue(
icon: Icons.thumb_up,
value: bike.likes.toString(),
),
],
)
],
),
),
],
),
);
}
}
class MetricValue extends StatelessWidget {
final IconData icon;
final String value;
MetricValue({this.icon, this.value});
@override
Widget build(BuildContext context) {
return Row(
children: <Widget>[
Icon(icon, size: 12.0),
Container(width: 4.0),
Text(
value,
style: TextStyle(fontSize: 12.0),
)
],
);
}
}
class Bike {
final String name;
final String description;
final int views;
final int likes;
Bike({
this.name,
this.description,
this.views,
this.likes,
});
}
class Bikes {
static final rnd = Random();
static final hellrider = Bike(
name: 'Hell Rider',
description: 'Best choice to thravel over highway to nether.',
views: randomMetric(),
likes: randomMetric(),
);
static final desertRoamer = Bike(
name: 'Desert Roamer',
description: 'Dissect dry seas with clouds of dust from your rear wheel.',
views: randomMetric(),
likes: randomMetric(),
);
static final lavaDozer = Bike(
name: 'Lava Dozer',
description:
'If you see a lava lump - simply bash through, this creature doesn\'t care.',
views: randomMetric(),
likes: randomMetric(),
);
static final swampEater = Bike(
name: 'Swamp Eater',
description:
'Was it a swap or a speedway? It passed away to fast to recognize!',
views: randomMetric(),
likes: randomMetric(),
);
static final dragonRoar = Bike(
name: 'Dragon Roar',
description:
'If I would be you, I would not stand too close to this thing when it is turned on.',
views: randomMetric(),
likes: randomMetric(),
);
}
int randomMetric() {
return 10000 + Bikes.rnd.nextInt(10000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment