Skip to content

Instantly share code, notes, and snippets.

@flexboni
Created November 27, 2023 01:20
Show Gist options
  • Save flexboni/9036b6a0671541ecc17fe6154aa395be to your computer and use it in GitHub Desktop.
Save flexboni/9036b6a0671541ecc17fe6154aa395be to your computer and use it in GitHub Desktop.
플러터챌린지 0일차 기본문제 - 김구봉
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Hello Flutter'),
leading: IconButton(
onPressed: () {},
icon: const Icon(Icons.home),
),
centerTitle: true,
actions: [
IconButton(
onPressed: () {},
icon: const Icon(Icons.question_mark_rounded),
),
],
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'Your score',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30),
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
Button(
onPressed: () {
setState(() {
++_counter;
});
},
text: '+',
),
const SizedBox(width: 20),
Button(
onPressed: () {
setState(() {
--_counter;
});
},
text: '-',
),
],
)
],
),
),
);
}
}
class Button extends StatelessWidget {
const Button({
super.key,
required this.text,
required this.onPressed,
});
final String text;
final void Function()? onPressed;
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: onPressed,
style: const ButtonStyle(
backgroundColor: MaterialStatePropertyAll(Colors.purple),
),
child: Text(
text,
style: const TextStyle(color: Colors.white),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment