Skip to content

Instantly share code, notes, and snippets.

@hardy716
Created January 28, 2024 14:20
Show Gist options
  • Save hardy716/afbb4cb5270bb8c0fdda4c0eaf95c2e2 to your computer and use it in GitHub Desktop.
Save hardy716/afbb4cb5270bb8c0fdda4c0eaf95c2e2 to your computer and use it in GitHub Desktop.
플러터챌린지 5일차 기본문제 - 신현호

플러터챌린지 5일차 기본문제 - 신현호

Created with <3 with dartpad.dev.

import 'package:flutter/material.dart';
final spaceData = {
'NGC 162': 1862, '87 Sylvia': 1866, 'R 136a1': 1985, '28978 Ixion': 2001, 'NGC 6715': 1778,
'94400 Hongdaeyong': 2001, '6354 Vangelis': 1934, 'C/2020 F3': 2020, 'Cartwheel Galaxy': 1941, 'Sculptor Dwarf Elliptical Galaxy': 1937,
'Eight-Burst Nebula': 1835, 'Rhea': 1672, 'C/1702 H1': 1702, 'Messier 5': 1702, 'Messier 50': 1711,
'Cassiopeia A': 1680, 'Great Comet of 1680': 1680, 'Butterfly Cluster': 1654, 'Triangulum Galaxy': 1654, 'Comet of 1729': 1729,
'Omega Nebula': 1745, 'Eagle Nebula': 1745, 'Small Sagittarius Star Cloud': 1764, 'Dumbbell Nebula': 1764, '54509 YORP': 2000,
'Dia': 2000, '63145 Choemuseon': 2000,
};
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'HelloListView',
debugShowCheckedModeBanner: false,
home: HelloListViewScreen(),
);
}
}
class HelloListViewScreen extends StatefulWidget {
@override
State<HelloListViewScreen> createState() => _HelloListViewScreenState();
}
class _HelloListViewScreenState extends State<HelloListViewScreen> {
final ScrollController _controller = ScrollController();
double currentScrollPosition = 0;
@override
void initState() {
super.initState();
_controller.addListener(() {
setState(() {
currentScrollPosition = _controller.offset;
});
});
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('My First List View!')),
body: Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
child: ListView.builder(
controller: _controller,
itemBuilder: (context, index) {
return _ListItem(
name: spaceData.keys.elementAt(index),
year: spaceData.values.elementAt(index),
);
},
itemCount: spaceData.length,
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
_controller.animateTo(
0,
duration: const Duration(milliseconds: 160),
curve: Curves.linear,
);
},
child: const Icon(Icons.navigation),
),
);
}
}
class _ListItem extends StatelessWidget {
final String name;
final int year;
const _ListItem({
required this.name,
required this.year
});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 6.0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(4),
border: Border.all(color: Colors.grey)),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Text('🛰️ $name was discovered in $year'),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment