Skip to content

Instantly share code, notes, and snippets.

@BoHellgren
Last active April 23, 2020 17:17
Show Gist options
  • Save BoHellgren/b08a2bf8b105c75529f60f5d6e8746d8 to your computer and use it in GitHub Desktop.
Save BoHellgren/b08a2bf8b105c75529f60f5d6e8746d8 to your computer and use it in GitHub Desktop.
Game main.dart step 1
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
textTheme: TextTheme(
body1: TextStyle(
fontSize: 16.0,
color: Colors.black,
backgroundColor: Colors.white),
)),
home: MyHomePage(),
);
}
}
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
void initState() {
super.initState();
// AdMob code will be added here
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Kill the gnats!'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
color: Colors.white,
height: 30.0,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('Your current level is x (y gnats)'),
FlatButton(
color: Colors.white,
textColor: Colors.white,
padding: EdgeInsets.all(0.0),
onPressed: () {
print('Reset button pressed');
setState(() {});
},
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(5.0)),
child: Text(" Reset ", style: TextStyle(fontSize: 18.0, backgroundColor: Colors.red[400]),
),
),
)
],
),
),
Expanded(
child: Container(
color: Colors.grey,
)),
Container(
color: Colors.lightGreen,
height: 100.0, // For largeBanner ads
)
],
),
),
floatingActionButton: Padding(
padding: const EdgeInsets.only(bottom: 100.0),
child: FloatingActionButton(
onPressed: () => _newGame(),
child: Icon(Icons.add),
),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
void _newGame() {
print('New game started.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment