|
| 1 | +import 'dart:ui'; |
| 2 | + |
| 3 | +import 'package:sorting_visulalization/main.dart'; |
| 4 | +import 'package:flutter/material.dart'; |
| 5 | +import 'package:sorting_visulalization/paints/bars.dart'; |
| 6 | +import 'package:sorting_visulalization/paints/dots.dart'; |
| 7 | +import 'package:sorting_visulalization/paints/multiple_shapes.dart'; |
| 8 | +import 'package:sorting_visulalization/paints/color.dart'; |
| 9 | +import 'package:sorting_visulalization/paints/pyramid.dart'; |
| 10 | + |
| 11 | +class MainBody extends StatelessWidget { |
| 12 | + const MainBody({ |
| 13 | + Key key, |
| 14 | + }) : super(key: key); |
| 15 | + |
| 16 | + @override |
| 17 | + Widget build(BuildContext context) { |
| 18 | + return SafeArea( |
| 19 | + child: Container( |
| 20 | + padding: const EdgeInsets.only(top: 0.0), |
| 21 | + child: StreamBuilder<Object>( |
| 22 | + initialData: numbers, |
| 23 | + stream: streamController.stream, |
| 24 | + builder: (context, snapshot) { |
| 25 | + List<int> numbers = snapshot.data; |
| 26 | + int counter = 0; |
| 27 | + screen_width = MediaQuery.of(context).size.width; |
| 28 | + screen_height = MediaQuery.of(context).size.height; |
| 29 | + switch (currentPlotStyle) { |
| 30 | + case 'bar': |
| 31 | + return Row( |
| 32 | + children: numbers.map((int num) { |
| 33 | + counter++; |
| 34 | + return Container( |
| 35 | + child: CustomPaint( |
| 36 | + painter: BarPainter( |
| 37 | + index: counter, |
| 38 | + value: num, |
| 39 | + width: MediaQuery.of(context).size.width / |
| 40 | + sampleSize), |
| 41 | + ), |
| 42 | + ); |
| 43 | + }).toList(), |
| 44 | + ); |
| 45 | + break; |
| 46 | + case 'dot': |
| 47 | + return Row( |
| 48 | + children: numbers.map((int num) { |
| 49 | + counter++; |
| 50 | + return Container( |
| 51 | + child: CustomPaint( |
| 52 | + painter: DotPainter( |
| 53 | + index: counter, |
| 54 | + value: num, |
| 55 | + width: MediaQuery.of(context).size.width / |
| 56 | + sampleSize), |
| 57 | + ), |
| 58 | + ); |
| 59 | + }).toList(), |
| 60 | + ); |
| 61 | + break; |
| 62 | + case 'multiple': |
| 63 | + return Row( |
| 64 | + children: numbers.map((int num) { |
| 65 | + counter++; |
| 66 | + return Container( |
| 67 | + child: CustomPaint( |
| 68 | + painter: MultiplePainter( |
| 69 | + index: counter, |
| 70 | + value: num, |
| 71 | + width: MediaQuery.of(context).size.width / |
| 72 | + sampleSize), |
| 73 | + ), |
| 74 | + ); |
| 75 | + }).toList(), |
| 76 | + ); |
| 77 | + break; |
| 78 | + case 'color': |
| 79 | + return Row( |
| 80 | + children: numbers.map((int num) { |
| 81 | + counter++; |
| 82 | + return Container( |
| 83 | + child: CustomPaint( |
| 84 | + painter: ColorPainter( |
| 85 | + index: counter, |
| 86 | + value: num, |
| 87 | + width: MediaQuery.of(context).size.width / |
| 88 | + sampleSize), |
| 89 | + ), |
| 90 | + ); |
| 91 | + }).toList(), |
| 92 | + ); |
| 93 | + break; |
| 94 | + case 'pyramid': |
| 95 | + return Row( |
| 96 | + children: numbers.map((int num) { |
| 97 | + counter++; |
| 98 | + return Container( |
| 99 | + child: CustomPaint( |
| 100 | + painter: PyramidPainter( |
| 101 | + index: counter, |
| 102 | + value: num, |
| 103 | + width: .9 * |
| 104 | + MediaQuery.of(context).size.height / |
| 105 | + sampleSize), |
| 106 | + ), |
| 107 | + ); |
| 108 | + }).toList(), |
| 109 | + ); |
| 110 | + break; |
| 111 | + } |
| 112 | + }), |
| 113 | + ), |
| 114 | + ); |
| 115 | + } |
| 116 | +} |
0 commit comments