Created
October 2, 2024 03:25
-
-
Save hongsw/a237c9815c179bc8d4ad57daf68dff3e to your computer and use it in GitHub Desktop.
my_flutter1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| void main() async { | |
| runApp(MaterialApp( | |
| initialRoute: '/', | |
| routes: { | |
| // When navigating to the "/" route, build the FirstScreen widget. | |
| '/': (context) => FirstScreen(), | |
| // When navigating to the "/second" route, build the SecondScreen widget. | |
| '/second': (context) => QuizPage(), | |
| }, | |
| onGenerateRoute: (RouteSettings settings) { | |
| // https://sharegpt.com/c/aPDwZ64 | |
| if (settings.name == '/result') { | |
| final Map<String, dynamic> arguments = | |
| settings.arguments as Map<String, dynamic>; | |
| return MaterialPageRoute( | |
| builder: (context) => ResultPage( | |
| correctAnswers: arguments['correctAnswers'] as int, | |
| totalQuestions: arguments['totalQuestions'] as int, | |
| ), | |
| ); | |
| } | |
| }, | |
| )); | |
| } | |
| class FirstScreen extends StatelessWidget { | |
| const FirstScreen({super.key}); | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar(title: const Text("Language learning app")), // ์๋จ ์ฑ๋ฐ | |
| body: SingleChildScrollView( | |
| // ์คํฌ๋กค์ด ๊ฐ๋ฅํ ์์ ฏ | |
| child: Column(children: [ | |
| const Placeholder( | |
| fallbackHeight: 200, // Placeholder์ ๋์ด๋ฅผ ์ง์ ํฉ๋๋ค. | |
| ), // ๋์ด๊ฐ 200์ธ ๋น ๋ฐ์ค | |
| SizedBox( | |
| height: 300, // | |
| child: SingleChildScrollView( | |
| // ์คํฌ๋กค์ด ๊ฐ๋ฅํ ์์ ฏ | |
| child: ListView.builder( | |
| shrinkWrap: true, // ๋ฆฌ์คํธ๋ทฐ์ ํฌ๊ธฐ๋ฅผ ์์ ์์ ฏ์ ๋ง์ถฅ๋๋ค. | |
| physics: | |
| const NeverScrollableScrollPhysics(), // ๋ฆฌ์คํธ๋ทฐ์์ ์คํฌ๋กค ๋์์ ๋ง์ต๋๋ค. | |
| itemCount: 17, // ์์ดํ ์ ๊ฐ์ | |
| itemBuilder: (BuildContext context, int index) { | |
| // ๋ฆฌ์คํธ๋ทฐ์ ์์ดํ ์ ๊ตฌ์ฑํ๋ ์์ ฏ | |
| return Card( | |
| // ์นด๋ ์์ ฏ | |
| child: ListTile( | |
| // ๋ฆฌ์คํธ ํ์ผ ์์ ฏ | |
| leading: | |
| FlutterLogo(size: 72.0), // ์นด๋์ ์ผ์ชฝ์ ์ด๋ฏธ์ง ์์ด์ฝ์ ํ์ํฉ๋๋ค. | |
| title: Text('Three-line ListTile'), // ๋ฆฌ์คํธ ํ์ผ์ ์ ๋ชฉ | |
| subtitle: Text( | |
| 'A sufficiently long subtitle warrants three lines. $index'), // ๋ฆฌ์คํธ ํ์ผ์ ๋ถ์ ๋ชฉ | |
| trailing: | |
| Icon(Icons.more_vert), // ๋ฆฌ์คํธ ํ์ผ์ ์ค๋ฅธ์ชฝ์ ํ์๋๋ ์ถ๊ฐ ์ ๋ณด ์์ด์ฝ | |
| isThreeLine: true, // ๋ฆฌ์คํธ ํ์ผ์ด ์ธ ์ค๋ก ๊ตฌ์ฑ๋ฉ๋๋ค. | |
| onTap: () { | |
| Navigator.pushNamed(context, | |
| '/second'); // ๋ฆฌ์คํธ ํ์ผ์ ํญํ๋ฉด /second ๊ฒฝ๋ก๋ก ์ด๋ํฉ๋๋ค. | |
| }, // Handle your onTap here. | |
| ), | |
| ); | |
| }, | |
| ))), | |
| const Placeholder( | |
| fallbackHeight: 200, // Placeholder์ ๋์ด๋ฅผ ์ง์ ํฉ๋๋ค. | |
| ), // ๋์ด๊ฐ 200์ธ ๋น ๋ฐ์ค | |
| ]))); | |
| } | |
| } | |
| // https://sharegpt.com/c/B3lxchS | |
| class QuizPage extends StatefulWidget { | |
| @override | |
| _QuizPageState createState() => _QuizPageState(); | |
| } | |
| class _QuizPageState extends State<QuizPage> { | |
| int _correctAnswers = 0; | |
| int _wrongAnswers = 0; | |
| int _currentIndex = 0; | |
| final List<Map<String, dynamic>> _questions = [ | |
| { | |
| 'question': 'apple', | |
| "answers": ['์ฌ๊ณผ', 'ํฌ๋', '๋ฐฐ'], | |
| 'correctIndex': 0, | |
| }, | |
| { | |
| 'question': 'banana', | |
| 'answers': ['๋ฐ๋๋', 'ํค์', '๋ธ๊ธฐ'], | |
| 'correctIndex': 0, | |
| }, | |
| { | |
| 'question': 'cherry', | |
| 'answers': ['์ฒด๋ฆฌ', '์๋ฐ', 'ํฌ๋'], | |
| 'correctIndex': 0, | |
| }, | |
| ]; | |
| void _onAnswerSelected(int selectedIndex) { | |
| setState(() { | |
| if (_questions[_currentIndex]['correctIndex'] == selectedIndex) { | |
| _correctAnswers++; | |
| } else { | |
| _wrongAnswers++; | |
| } | |
| if (_currentIndex == _questions.length - 1) { | |
| Navigator.pushNamed( | |
| context, | |
| '/result', | |
| arguments: { | |
| 'correctAnswers': _correctAnswers, | |
| 'totalQuestions': _questions.length | |
| }, | |
| ); | |
| } else { | |
| _currentIndex++; | |
| } | |
| }); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar( | |
| title: Text('ํด์ฆ'), | |
| ), | |
| body: Column( | |
| children: [ | |
| SizedBox(height: 16), | |
| LinearProgressIndicator( | |
| value: (_currentIndex + 1) / _questions.length, | |
| backgroundColor: Colors.grey[300], | |
| valueColor: AlwaysStoppedAnimation<Color>(Colors.blue), | |
| ), | |
| SizedBox(height: 16), | |
| Padding( | |
| padding: const EdgeInsets.symmetric(horizontal: 16), | |
| child: Text( | |
| '๋ฌธ์ ${_currentIndex + 1}/${_questions.length}', | |
| style: TextStyle(fontSize: 16), | |
| ), | |
| ), | |
| SizedBox(height: 16), | |
| Expanded( | |
| child: Card( | |
| margin: const EdgeInsets.symmetric(horizontal: 5), | |
| elevation: 4, | |
| child: Padding( | |
| padding: const EdgeInsets.all(16), | |
| child: Column( | |
| mainAxisAlignment: MainAxisAlignment.spaceAround, | |
| children: [ | |
| Text( | |
| _questions[_currentIndex]['question'], | |
| style: TextStyle(fontSize: 28), | |
| ), | |
| ...(_questions[_currentIndex]['answers'] as List<String>) | |
| .asMap() | |
| .entries | |
| .map( | |
| (entry) => ElevatedButton( | |
| onPressed: () => _onAnswerSelected(entry.key), | |
| child: Text( | |
| entry.value, | |
| style: TextStyle(fontSize: 20), | |
| ), | |
| ), | |
| ) | |
| .toList(), | |
| ], | |
| ), | |
| ), | |
| ), | |
| ), | |
| ], | |
| ), | |
| ); | |
| } | |
| } | |
| // https://sharegpt.com/c/aPDwZ64 | |
| class ResultPage extends StatelessWidget { | |
| final int correctAnswers; | |
| final int totalQuestions; | |
| ResultPage({required this.correctAnswers, required this.totalQuestions}); | |
| String get resultPhrase { | |
| double percentage = correctAnswers / totalQuestions; | |
| if (percentage >= 0.9) { | |
| return '๋๋จํด์!'; | |
| } else if (percentage >= 0.7) { | |
| return '์ํ์ด์!'; | |
| } else if (percentage >= 0.5) { | |
| return '์ข ๋ ๋ ธ๋ ฅํด์ฃผ์ธ์'; | |
| } else { | |
| return '๋ถ๋ฐํ์ธ์!'; | |
| } | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar( | |
| title: Text('๊ฒฐ๊ณผ'), | |
| ), | |
| body: Padding( | |
| padding: const EdgeInsets.all(16), | |
| child: Column( | |
| mainAxisAlignment: MainAxisAlignment.center, | |
| crossAxisAlignment: CrossAxisAlignment.center, | |
| children: [ | |
| Text( | |
| resultPhrase, | |
| style: TextStyle(fontSize: 24), | |
| textAlign: TextAlign.center, | |
| ), | |
| SizedBox(height: 16), | |
| Text( | |
| '๋ง์ ๊ฐ์: $correctAnswers/$totalQuestions', | |
| style: TextStyle(fontSize: 20), | |
| ), | |
| SizedBox(height: 16), | |
| ElevatedButton( | |
| onPressed: () { | |
| Navigator.pushNamedAndRemoveUntil( | |
| context, | |
| '/', | |
| (route) => false, | |
| ); | |
| }, | |
| child: Text('ํ์ผ๋ก'), | |
| ), | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment