v5-old
This commit is contained in:
@@ -9,7 +9,7 @@ import '../../../pages/empty/empty_page.dart';
|
|||||||
import '../../../pages/settings/settings_page.dart';
|
import '../../../pages/settings/settings_page.dart';
|
||||||
import '../../../pages/user/user_page.dart';
|
import '../../../pages/user/user_page.dart';
|
||||||
import '../../../pages/counter/counter_page.dart';
|
import '../../../pages/counter/counter_page.dart';
|
||||||
import '../../../pages/sort/sort_page.dart';
|
import '../../../pages/sort/views/sort_page.dart';
|
||||||
import '../transition/fade_transition_page.dart';
|
import '../transition/fade_transition_page.dart';
|
||||||
import '../../../pages/color/color_add_page.dart';
|
import '../../../pages/color/color_add_page.dart';
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:iroute/v5/pages/sort/provider/sort_config.dart';
|
import 'package:iroute/v5/pages/sort/bloc/sort_config.dart';
|
||||||
import '../../../pages/sort/sort_setting.dart';
|
import '../../../pages/sort/sort_setting.dart';
|
||||||
import '../router/app_router_delegate.dart';
|
import '../router/app_router_delegate.dart';
|
||||||
import 'app_navigation_rail.dart';
|
import 'app_navigation_rail.dart';
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import 'package:flutter/cupertino.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:iroute/components/toly_ui/button/hover_icon_button.dart';
|
import 'package:iroute/components/toly_ui/button/hover_icon_button.dart';
|
||||||
import 'package:iroute/components/toly_ui/popable/drop_selectable_widget.dart';
|
import 'package:iroute/components/toly_ui/popable/drop_selectable_widget.dart';
|
||||||
import 'package:iroute/v5/pages/sort/provider/sort_config.dart';
|
import 'package:iroute/v5/pages/sort/bloc/sort_config.dart';
|
||||||
import '../../../pages/sort/functions.dart';
|
import '../../../pages/sort/functions.dart';
|
||||||
import '../router/app_router_delegate.dart';
|
import '../router/app_router_delegate.dart';
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import '../pages/sort/bloc/state.dart';
|
||||||
import 'navigation/router/app_router_delegate.dart';
|
import 'navigation/router/app_router_delegate.dart';
|
||||||
import 'navigation/views/app_navigation.dart';
|
import 'navigation/views/app_navigation.dart';
|
||||||
import 'navigation/views/app_navigation_rail.dart';
|
import 'navigation/views/app_navigation_rail.dart';
|
||||||
@@ -8,20 +9,23 @@ class UnitApp extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return SortStateScope(
|
||||||
theme: ThemeData(
|
notifier: SortState(),
|
||||||
fontFamily: "宋体",
|
child: MaterialApp(
|
||||||
scaffoldBackgroundColor: Colors.white,
|
theme: ThemeData(
|
||||||
appBarTheme: const AppBarTheme(
|
fontFamily: "宋体",
|
||||||
elevation: 0,
|
scaffoldBackgroundColor: Colors.white,
|
||||||
iconTheme: IconThemeData(color: Colors.black),
|
appBarTheme: const AppBarTheme(
|
||||||
titleTextStyle: TextStyle(
|
elevation: 0,
|
||||||
color: Colors.black,
|
iconTheme: IconThemeData(color: Colors.black),
|
||||||
fontSize: 18,
|
titleTextStyle: TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
color: Colors.black,
|
||||||
))),
|
fontSize: 18,
|
||||||
debugShowCheckedModeBanner: false,
|
fontWeight: FontWeight.bold,
|
||||||
home: AppNavigation()
|
))),
|
||||||
|
debugShowCheckedModeBanner: false,
|
||||||
|
home: AppNavigation()
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,13 @@ class SortConfig {
|
|||||||
final int count;
|
final int count;
|
||||||
final int seed;
|
final int seed;
|
||||||
final Duration duration;
|
final Duration duration;
|
||||||
|
final String name;
|
||||||
|
|
||||||
SortConfig(this.count, this.duration,this.seed);
|
SortConfig(this.count, this.duration,this.seed,this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
final ValueNotifier<SortConfig> sortConfig = ValueNotifier(
|
final ValueNotifier<SortConfig> sortConfig = ValueNotifier(
|
||||||
SortConfig(-1, const Duration(microseconds: 1500),-1),
|
SortConfig(-1, const Duration(microseconds: 1500),-1,'quick'),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
77
lib/v5/pages/sort/bloc/state.dart
Normal file
77
lib/v5/pages/sort/bloc/state.dart
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
import 'dart:math';
|
||||||
|
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
|
||||||
|
import '../functions.dart';
|
||||||
|
import 'sort_config.dart';
|
||||||
|
|
||||||
|
enum SortStatus{
|
||||||
|
none, // 未操作
|
||||||
|
sorting, // 排序中
|
||||||
|
sorted, // 排序完成
|
||||||
|
}
|
||||||
|
|
||||||
|
class SortState with ChangeNotifier{
|
||||||
|
|
||||||
|
SortStatus status = SortStatus.none;
|
||||||
|
|
||||||
|
List<int> data = [];
|
||||||
|
|
||||||
|
SortConfig _config = SortConfig(-1, const Duration(microseconds: 1500),-1,'quick');
|
||||||
|
SortConfig get config => _config;
|
||||||
|
Random random = Random();
|
||||||
|
|
||||||
|
set config(SortConfig config){
|
||||||
|
_config = config;
|
||||||
|
reset(_zoneSize);
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
Size _zoneSize = Size.zero;
|
||||||
|
|
||||||
|
void reset(Size zoneSize){
|
||||||
|
_zoneSize = zoneSize;
|
||||||
|
status = SortStatus.sorting;
|
||||||
|
int count = config.count;
|
||||||
|
if(count==-1){
|
||||||
|
count = zoneSize.width~/2;
|
||||||
|
}
|
||||||
|
if(config.seed!=-1){
|
||||||
|
random = Random(config.seed);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
//随机往数组中填值
|
||||||
|
data.add(random.nextInt(zoneSize.height.toInt()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sort() async{
|
||||||
|
status = SortStatus.sorting;
|
||||||
|
notifyListeners();
|
||||||
|
Stopwatch stopwatch = Stopwatch()..start();
|
||||||
|
SortFunction? sortFunction = sortFunctionMap[config.name];
|
||||||
|
if(sortFunction!=null){
|
||||||
|
await sortFunction(data,(arr) async {
|
||||||
|
await Future.delayed(config.duration);
|
||||||
|
data = arr;
|
||||||
|
notifyListeners();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
status = SortStatus.sorted;
|
||||||
|
notifyListeners();
|
||||||
|
stopwatch.stop();
|
||||||
|
print("Sorting completed in ${stopwatch.elapsed.inMilliseconds} ms.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Provides the current [SortState] to descendant widgets in the tree.
|
||||||
|
class SortStateScope extends InheritedNotifier<SortState> {
|
||||||
|
const SortStateScope({
|
||||||
|
required super.notifier,
|
||||||
|
required super.child,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
static SortState of(BuildContext context) =>
|
||||||
|
context.dependOnInheritedWidgetOfExactType<SortStateScope>()!.notifier!;
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'provider/sort_config.dart';
|
import 'bloc/sort_config.dart';
|
||||||
|
|
||||||
class SortSettings extends StatefulWidget {
|
class SortSettings extends StatefulWidget {
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ class _SortSettingsState extends State<SortSettings> {
|
|||||||
|
|
||||||
sortConfig.value = SortConfig(int.parse(_count.text), Duration(
|
sortConfig.value = SortConfig(int.parse(_count.text), Duration(
|
||||||
microseconds: int.parse(_duration.text),
|
microseconds: int.parse(_duration.text),
|
||||||
),int.parse(_seed.text));
|
),int.parse(_seed.text),sortConfig.value.name);
|
||||||
|
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}, child: Text('确定设置'))
|
}, child: Text('确定设置'))
|
||||||
|
|||||||
60
lib/v5/pages/sort/views/data_painter.dart
Normal file
60
lib/v5/pages/sort/views/data_painter.dart
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class DataPainter extends CustomPainter{
|
||||||
|
|
||||||
|
final List<int> data;
|
||||||
|
|
||||||
|
DataPainter({required this.data});
|
||||||
|
|
||||||
|
@override
|
||||||
|
void paint(Canvas canvas, Size size) {
|
||||||
|
double itemWidth = size.width/data.length;
|
||||||
|
double height = size.height;
|
||||||
|
|
||||||
|
Paint paint = Paint();
|
||||||
|
paint.strokeWidth = itemWidth;
|
||||||
|
paint.strokeCap = StrokeCap.round;
|
||||||
|
|
||||||
|
for(int i=0;i<data.length;i++){
|
||||||
|
int value = data[i];
|
||||||
|
if (value < height * .10) {
|
||||||
|
paint.color = Colors.blue.shade100;
|
||||||
|
} else if (value < height * .20) {
|
||||||
|
paint.color = Colors.blue.shade200;
|
||||||
|
} else if (value < height * .30) {
|
||||||
|
paint.color = Colors.blue.shade300;
|
||||||
|
} else if (value < height * .40) {
|
||||||
|
paint.color = Colors.blue.shade400;
|
||||||
|
} else if (value < height * .50) {
|
||||||
|
paint.color = Colors.blue.shade500;
|
||||||
|
} else if (value < height * .60) {
|
||||||
|
paint.color = Colors.blue.shade600;
|
||||||
|
} else if (value < height * .70) {
|
||||||
|
paint.color = Colors.blue.shade700;
|
||||||
|
} else if (value < height * .80) {
|
||||||
|
paint.color = Colors.blue.shade800;
|
||||||
|
} else if (value < height * .90) {
|
||||||
|
paint.color = Colors.blue.shade900;
|
||||||
|
} else {
|
||||||
|
paint.color = const Color(0xFF011E51);
|
||||||
|
}
|
||||||
|
canvas.drawLine(
|
||||||
|
Offset(i * itemWidth+itemWidth/2, 0),
|
||||||
|
Offset(
|
||||||
|
i * itemWidth+itemWidth/2,
|
||||||
|
value.ceilToDouble(),
|
||||||
|
),
|
||||||
|
paint);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool shouldRepaint(covariant DataPainter oldDelegate) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,8 +3,10 @@ import 'dart:math';
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'functions.dart';
|
import '../bloc/state.dart';
|
||||||
import 'provider/sort_config.dart';
|
import '../functions.dart';
|
||||||
|
import '../bloc/sort_config.dart';
|
||||||
|
import 'data_painter.dart';
|
||||||
|
|
||||||
class SortPage extends StatefulWidget {
|
class SortPage extends StatefulWidget {
|
||||||
final Size size;
|
final Size size;
|
||||||
@@ -92,15 +94,14 @@ class _SortPageState extends State<SortPage> {
|
|||||||
if(count==-1){
|
if(count==-1){
|
||||||
s = widget.size.width~/2;
|
s = widget.size.width~/2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sortConfig.value.seed!=-1){
|
if(sortConfig.value.seed!=-1){
|
||||||
random = Random(sortConfig.value.seed);
|
random = Random(sortConfig.value.seed);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < s; i++) {
|
|
||||||
|
|
||||||
|
for (int i = 0; i < s; i++) {
|
||||||
//随机往数组中填值
|
//随机往数组中填值
|
||||||
numbers.add(random.nextInt(widget.size.height.toInt()));
|
numbers.add(random.nextInt(widget.size.height.toInt()));
|
||||||
|
|
||||||
//numbers.add(Random().nextInt();
|
|
||||||
}
|
}
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
@@ -114,6 +115,9 @@ class _SortPageState extends State<SortPage> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
|
List<int> numbers = SortStateScope.of(context).data;
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
child: Icon(Icons.run_circle_outlined),
|
child: Icon(Icons.run_circle_outlined),
|
||||||
@@ -126,17 +130,9 @@ class _SortPageState extends State<SortPage> {
|
|||||||
stream: streamController.stream,
|
stream: streamController.stream,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
List<int> numbers = snapshot.data as List<int>;
|
List<int> numbers = snapshot.data as List<int>;
|
||||||
return Row(
|
return CustomPaint(
|
||||||
children: numbers.asMap().keys.map((int index) {
|
size: widget.size,
|
||||||
return CustomPaint(
|
painter: DataPainter(data: numbers),
|
||||||
painter: BarPainter(
|
|
||||||
height: widget.size.height,
|
|
||||||
width: widget.size.width/numbers.length,
|
|
||||||
value: numbers[index],
|
|
||||||
index: index,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}).toList(),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Reference in New Issue
Block a user