Created
September 15, 2021 08:46
-
-
Save doyle-flutter/489e36da97d287ea34dec5dd50aff89c to your computer and use it in GitHub Desktop.
[ Flutter - Preview ] 수학 문제 및 필기 어플++ - 2020 수능 수학 문제
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 'dart:ui'; | |
| import 'package:flutter/material.dart'; | |
| class MathController{} | |
| class Math extends StatelessWidget { | |
| Math({Key? key}) : super(key: key); | |
| static const String path = "/math"; | |
| final MathController _mathController = MathController(); | |
| @override | |
| Widget build(BuildContext context) => MathView(controller: this._mathController); | |
| } | |
| class MathView extends StatefulWidget { | |
| final MathController controller; | |
| MathView({Key? key, required this.controller}) : super(key: key); | |
| @override | |
| State<MathView> createState() => _MathViewState(); | |
| } | |
| class _MathViewState extends State<MathView> { | |
| List<List<Offset?>> offsets = [<Offset?>[]]; | |
| bool isPainter = false; | |
| int? selectNumber; | |
| int pageNumber = 0; | |
| @override | |
| Widget build(BuildContext context) => Scaffold( | |
| appBar: AppBar( | |
| title: Text("JamesMath"), | |
| centerTitle: true, | |
| actions: [ | |
| IconButton( | |
| icon: Icon(Icons.skip_previous), | |
| onPressed: this.pageNumber == 0 ? null : () => setState(() => this.pageNumber--) | |
| ), | |
| IconButton( | |
| icon: Icon(Icons.navigate_next), | |
| onPressed: (){ | |
| setState((){ | |
| this.offsets.add(<Offset?>[]); | |
| this.pageNumber++; | |
| }); | |
| } | |
| ), | |
| ] | |
| ), | |
| floatingActionButton: FloatingActionButton( | |
| child: Icon(Icons.play_arrow), | |
| onPressed: this.selectNumber == null ? null : () async{ | |
| setState(() => this.isPainter = false); | |
| await showDialog( | |
| context: context, | |
| builder: (BuildContext context) => AlertDialog( | |
| title: Text(this.selectNumber == 2 ? "정답 👍" : "🔥 오답, 다시풀어주세요"), | |
| actions: [ | |
| TextButton( | |
| child: Text("닫기"), | |
| onPressed: () => Navigator.of(context).pop() | |
| ), | |
| TextButton( | |
| child: Text("새로 풀기"), | |
| onPressed: (){ | |
| setState(() { | |
| this.selectNumber = null; | |
| this.offsets = [<Offset?>[]]; | |
| this.pageNumber = 0; | |
| }); | |
| Navigator.of(context).pop(); | |
| } | |
| ) | |
| ], | |
| ) | |
| ); | |
| }, | |
| ), | |
| bottomNavigationBar: BottomAppBar( | |
| child: Container( | |
| child: Row( | |
| children: [ | |
| Expanded( | |
| child: IconButton( | |
| icon: this.isPainter ? Icon(Icons.lock_open_rounded,) : Icon(Icons.lock, color: Colors.red), | |
| onPressed: () => setState(() => this.isPainter = !this.isPainter), | |
| ), | |
| ), | |
| Expanded( | |
| child: IconButton( | |
| icon: Icon(Icons.close), | |
| onPressed: () => setState(() { | |
| this.offsets = [<Offset?>[]]; | |
| this.pageNumber = 0; | |
| }), | |
| ), | |
| ) | |
| ], | |
| ) | |
| ), | |
| ), | |
| body: Stack( | |
| alignment: Alignment.center, | |
| children: [ | |
| Container( | |
| child: GestureDetector( | |
| onPanDown: (details) { | |
| if(!this.isPainter) return; | |
| RenderBox _renderBox = context.findRenderObject() as RenderBox; | |
| Offset _localPosition = _renderBox.globalToLocal(details.globalPosition); | |
| setState(() { | |
| this.offsets[this.pageNumber].add(Offset(_localPosition.dx, _localPosition.dy-MediaQuery.of(context).padding.top - kToolbarHeight)); | |
| }); | |
| }, | |
| onPanUpdate: (details) { | |
| if(!this.isPainter) return; | |
| RenderBox _renderBox = context.findRenderObject() as RenderBox; | |
| Offset _localPosition = _renderBox.globalToLocal(details.globalPosition); | |
| setState(() { | |
| this.offsets[this.pageNumber].add(Offset(_localPosition.dx, _localPosition.dy-MediaQuery.of(context).padding.top - kToolbarHeight)); | |
| }); | |
| }, | |
| onPanEnd: (details) { | |
| if(!this.isPainter) return; | |
| setState(() { | |
| this.offsets[this.pageNumber].add(null); | |
| }); | |
| }, | |
| child: CustomPaint( | |
| painter: MathPainter(this.offsets[this.pageNumber]), | |
| child: Container( | |
| child: Column( | |
| children: [ | |
| Container( | |
| padding: EdgeInsets.all(30.0), | |
| child: Column( | |
| crossAxisAlignment: CrossAxisAlignment.start, | |
| mainAxisAlignment: MainAxisAlignment.center, | |
| children: [ | |
| Text( | |
| "2020 수능 수학(가형 / 홀수형)", | |
| style: TextStyle( | |
| color: Colors.red | |
| ) | |
| ), | |
| Text( | |
| "3. 좌표공간의 두 점 A(2,0,1), B(3,2,0)에서 같은 거리에 있는 y축 위의 점의 좌표가 (0, a, 0) 일 때, a의 값은? [2점]", | |
| style: TextStyle( | |
| fontSize: 20.0 | |
| ), | |
| ), | |
| ], | |
| ), | |
| ), | |
| Container( | |
| margin: EdgeInsets.symmetric( | |
| horizontal: 10.0 | |
| ), | |
| child: Row( | |
| children: <int>[1,2,3,4,5].map<Widget>( | |
| (int s) => Expanded( | |
| child: Container( | |
| margin: EdgeInsets.symmetric( | |
| horizontal: 4.0 | |
| ), | |
| child: MaterialButton( | |
| color: this.selectNumber == s ? Colors.red : Colors.grey[200], | |
| child: Text(s.toString()), | |
| shape: RoundedRectangleBorder( | |
| borderRadius: BorderRadius.circular(50.0) | |
| ), | |
| textColor: this.selectNumber == s ? Colors.white : Colors.black, | |
| onPressed: () => setState(() => this.selectNumber = s), | |
| ), | |
| ), | |
| ) | |
| ).toList(), | |
| ), | |
| ), | |
| ], | |
| ) | |
| ), | |
| ), | |
| ), | |
| ), | |
| Positioned( | |
| bottom: 20.0, | |
| child: Container( | |
| child: Text( | |
| "p.${this.pageNumber+1}", | |
| style: TextStyle( | |
| color: Colors.grey | |
| ) | |
| ), | |
| ) | |
| ) | |
| ], | |
| ) | |
| ); | |
| } | |
| class MathPainter extends CustomPainter { | |
| final List<Offset?> offsets; | |
| MathPainter(this.offsets) : super(); | |
| @override | |
| void paint(Canvas canvas, Size size) { | |
| final paint = Paint() | |
| ..color = Colors.deepPurple | |
| ..isAntiAlias = true | |
| ..strokeWidth = 3.0; | |
| if(this.offsets.isEmpty) return; | |
| for (var i = 0; i < offsets.length; i++) { | |
| if(offsets[i] != null){ | |
| if (shouldDrawLine(i)) { | |
| canvas.drawLine(offsets[i]!, offsets[i + 1]!, paint); | |
| } else if (shouldDrawPoint(i)) { | |
| canvas.drawPoints(PointMode.points, [offsets[i]!], paint); | |
| } | |
| } | |
| } | |
| } | |
| bool shouldDrawPoint(int i) => offsets[i] != null && offsets.length > i + 1 && offsets[i + 1] == null; | |
| bool shouldDrawLine(int i) => offsets[i] != null && offsets.length > i + 1 && offsets[i + 1] != null; | |
| @override | |
| bool shouldRepaint(CustomPainter oldDelegate) => true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment