v5。
This commit is contained in:
@@ -113,6 +113,7 @@ class _DropSelectableWidgetState extends State<DropSelectableWidget>
|
|||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
|
width: _focused ?1:1/View.of(context).devicePixelRatio,
|
||||||
color: _focused ? Colors.blue : widget.disableColor,
|
color: _focused ? Colors.blue : widget.disableColor,
|
||||||
)),
|
)),
|
||||||
child: Row(
|
child: Row(
|
||||||
|
|||||||
@@ -98,8 +98,7 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
|
|||||||
child = const CounterPage();
|
child = const CounterPage();
|
||||||
}
|
}
|
||||||
if (path == kDestinationsPaths[2]) {
|
if (path == kDestinationsPaths[2]) {
|
||||||
child = LayoutBuilder(
|
child = SortPage();
|
||||||
builder: (_,cts)=> SortPage(size: Size(cts.maxWidth,cts.maxHeight),));
|
|
||||||
}
|
}
|
||||||
if (path == kDestinationsPaths[3]) {
|
if (path == kDestinationsPaths[3]) {
|
||||||
child = const UserPage();
|
child = const UserPage();
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.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';
|
||||||
@@ -13,7 +12,7 @@ class AppNavigation extends StatelessWidget {
|
|||||||
double px1 = 1/View.of(context).devicePixelRatio;
|
double px1 = 1/View.of(context).devicePixelRatio;
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
endDrawer: Drawer(
|
endDrawer: Drawer(
|
||||||
child: SortSettings(config: sortConfig.value,),
|
child: SortSettings(),
|
||||||
),
|
),
|
||||||
body: Row(
|
body: Row(
|
||||||
children: [
|
children: [
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ 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/bloc/sort_config.dart';
|
|
||||||
import '../../../pages/sort/functions.dart';
|
import '../../../pages/sort/functions.dart';
|
||||||
|
import '../../../pages/sort/views/sort_bar.dart';
|
||||||
|
import '../../../pages/sort/views/sort_button.dart';
|
||||||
import '../router/app_router_delegate.dart';
|
import '../router/app_router_delegate.dart';
|
||||||
|
|
||||||
class AppRouterEditor extends StatefulWidget {
|
class AppRouterEditor extends StatefulWidget {
|
||||||
@@ -28,6 +29,9 @@ class _AppRouterEditorState extends State<AppRouterEditor> {
|
|||||||
|
|
||||||
void _onRouteChange() {
|
void _onRouteChange() {
|
||||||
_controller.text=router.path;
|
_controller.text=router.path;
|
||||||
|
setState(() {
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -39,58 +43,37 @@ class _AppRouterEditorState extends State<AppRouterEditor> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
print(router.path);
|
||||||
|
if(router.path=='/sort'){
|
||||||
|
return SortBar();
|
||||||
|
}
|
||||||
|
|
||||||
return Row(
|
return SizedBox(
|
||||||
children: [
|
width: 250,
|
||||||
DropSelectableWidget(
|
child: Stack(
|
||||||
fontSize: 12,
|
alignment: Alignment.centerRight,
|
||||||
data: sortNameMap.values.toList(),
|
children: [
|
||||||
iconSize: 20,
|
SizedBox(
|
||||||
height: 30,
|
child: CupertinoTextField(
|
||||||
width: 200,
|
controller: _controller,
|
||||||
disableColor: const Color(0xff1F425F),
|
style: TextStyle(fontSize: 14),
|
||||||
onDropSelected: (int index) async {
|
padding: EdgeInsets.only(left:12,top: 6,bottom: 6,right: 32),
|
||||||
sortName.value=sortNameMap.keys.toList()[index];
|
placeholder: '输入路由地址导航',
|
||||||
// curveAnim = CurvedAnimation(
|
onSubmitted: widget.onSubmit,
|
||||||
// parent: _ctrl, curve: maps.values.toList()[index]);
|
decoration: BoxDecoration(color: Color(0xffF1F2F3),borderRadius: BorderRadius.circular(6)),
|
||||||
// _startAnim();
|
),
|
||||||
},
|
|
||||||
),
|
|
||||||
const SizedBox(width: 10,),
|
|
||||||
GestureDetector(
|
|
||||||
onTap: (){
|
|
||||||
Scaffold.of(context).openEndDrawer();
|
|
||||||
// showDialog(
|
|
||||||
// useRootNavigator: false,
|
|
||||||
// context: context, builder: (ctx)=>AlertDialog());
|
|
||||||
},
|
|
||||||
child: const Icon(Icons.settings))
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
return Stack(
|
|
||||||
alignment: Alignment.centerRight,
|
|
||||||
children: [
|
|
||||||
SizedBox(
|
|
||||||
child: CupertinoTextField(
|
|
||||||
controller: _controller,
|
|
||||||
style: TextStyle(fontSize: 14),
|
|
||||||
padding: EdgeInsets.only(left:12,top: 6,bottom: 6,right: 32),
|
|
||||||
placeholder: '输入路由地址导航',
|
|
||||||
onSubmitted: widget.onSubmit,
|
|
||||||
decoration: BoxDecoration(color: Color(0xffF1F2F3),borderRadius: BorderRadius.circular(6)),
|
|
||||||
),
|
),
|
||||||
),
|
Padding(
|
||||||
Padding(
|
padding: const EdgeInsets.only(right: 8.0),
|
||||||
padding: const EdgeInsets.only(right: 8.0),
|
child: HoverIconButton(
|
||||||
child: HoverIconButton(
|
icon: Icons.directions_outlined,
|
||||||
icon: Icons.directions_outlined,
|
defaultColor: Color(0xff68696B),
|
||||||
defaultColor: Color(0xff68696B),
|
onPressed:()=>widget.onSubmit?.call(_controller.text),
|
||||||
onPressed:()=>widget.onSubmit?.call(_controller.text),
|
size: 20
|
||||||
size: 20
|
),
|
||||||
),
|
)
|
||||||
)
|
],
|
||||||
],
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../pages/sort/bloc/state.dart';
|
import '../pages/sort/provider/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';
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
import 'dart:ui';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class SortConfig {
|
|
||||||
final int count;
|
|
||||||
final int seed;
|
|
||||||
final Duration duration;
|
|
||||||
final String name;
|
|
||||||
|
|
||||||
SortConfig(this.count, this.duration,this.seed,this.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
final ValueNotifier<SortConfig> sortConfig = ValueNotifier(
|
|
||||||
SortConfig(-1, const Duration(microseconds: 1500),-1,'quick'),
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
final ValueNotifier<String> sortName = ValueNotifier('quick');
|
|
||||||
31
lib/v5/pages/sort/provider/sort_config.dart
Normal file
31
lib/v5/pages/sort/provider/sort_config.dart
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import 'dart:ui';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class SortConfig {
|
||||||
|
final int count;
|
||||||
|
final int seed;
|
||||||
|
final Duration duration;
|
||||||
|
final String name;
|
||||||
|
|
||||||
|
SortConfig({
|
||||||
|
this.count = 100,
|
||||||
|
this.duration = const Duration(microseconds: 1500),
|
||||||
|
this.seed = -1,
|
||||||
|
this.name = 'insertion',
|
||||||
|
});
|
||||||
|
|
||||||
|
SortConfig copyWith({
|
||||||
|
int? count,
|
||||||
|
int? seed,
|
||||||
|
Duration? duration,
|
||||||
|
String? name,
|
||||||
|
}) =>
|
||||||
|
SortConfig(
|
||||||
|
count:count??this.count,
|
||||||
|
seed:seed??this.seed,
|
||||||
|
duration:duration??this.duration,
|
||||||
|
name:name??this.name,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -13,35 +13,37 @@ enum SortStatus{
|
|||||||
|
|
||||||
class SortState with ChangeNotifier{
|
class SortState with ChangeNotifier{
|
||||||
|
|
||||||
|
SortState(){
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
SortStatus status = SortStatus.none;
|
SortStatus status = SortStatus.none;
|
||||||
|
|
||||||
List<int> data = [];
|
List<int> data = [];
|
||||||
|
List<int> stepData = [];
|
||||||
|
|
||||||
SortConfig _config = SortConfig(-1, const Duration(microseconds: 1500),-1,'quick');
|
SortConfig _config = SortConfig();
|
||||||
SortConfig get config => _config;
|
SortConfig get config => _config;
|
||||||
Random random = Random();
|
Random random = Random();
|
||||||
|
|
||||||
set config(SortConfig config){
|
set config(SortConfig config){
|
||||||
_config = config;
|
_config = config;
|
||||||
reset(_zoneSize);
|
reset();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
Size _zoneSize = Size.zero;
|
|
||||||
|
|
||||||
void reset(Size zoneSize){
|
void reset(){
|
||||||
_zoneSize = zoneSize;
|
data.clear();
|
||||||
status = SortStatus.sorting;
|
status = SortStatus.none;
|
||||||
|
notifyListeners();
|
||||||
int count = config.count;
|
int count = config.count;
|
||||||
if(count==-1){
|
|
||||||
count = zoneSize.width~/2;
|
|
||||||
}
|
|
||||||
if(config.seed!=-1){
|
if(config.seed!=-1){
|
||||||
random = Random(config.seed);
|
random = Random(config.seed);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
//随机往数组中填值
|
//随机往数组中填值
|
||||||
data.add(random.nextInt(zoneSize.height.toInt()));
|
data.add(random.nextInt(1000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +55,6 @@ class SortState with ChangeNotifier{
|
|||||||
if(sortFunction!=null){
|
if(sortFunction!=null){
|
||||||
await sortFunction(data,(arr) async {
|
await sortFunction(data,(arr) async {
|
||||||
await Future.delayed(config.duration);
|
await Future.delayed(config.duration);
|
||||||
data = arr;
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1,34 +1,38 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'bloc/sort_config.dart';
|
import 'provider/sort_config.dart';
|
||||||
|
import 'provider/state.dart';
|
||||||
|
|
||||||
class SortSettings extends StatefulWidget {
|
class SortSettings extends StatefulWidget {
|
||||||
|
|
||||||
final SortConfig config;
|
const SortSettings({super.key,});
|
||||||
|
|
||||||
const SortSettings({super.key,required this.config});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<SortSettings> createState() => _SortSettingsState();
|
State<SortSettings> createState() => _SortSettingsState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SortSettingsState extends State<SortSettings> {
|
class _SortSettingsState extends State<SortSettings> {
|
||||||
|
late TextEditingController _count =
|
||||||
|
TextEditingController();
|
||||||
|
late TextEditingController _duration = TextEditingController();
|
||||||
|
late TextEditingController _seed =
|
||||||
|
TextEditingController();
|
||||||
|
|
||||||
late TextEditingController _count = TextEditingController(
|
|
||||||
text:sortConfig.value.count.toString()
|
|
||||||
);
|
|
||||||
late TextEditingController _duration = TextEditingController(
|
|
||||||
text:sortConfig.value.duration.inMicroseconds.toString()
|
|
||||||
);
|
|
||||||
late TextEditingController _seed = TextEditingController(
|
|
||||||
text:sortConfig.value.seed.toString()
|
|
||||||
);
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
// TODO: implement initState
|
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
print('========_SortSettingsState#didChangeDependencies=============');
|
||||||
|
super.didChangeDependencies();
|
||||||
|
SortState state = SortStateScope.of(context);
|
||||||
|
_count.text = state.config.count.toString();
|
||||||
|
_duration.text = state.config.duration.inMicroseconds.toString();
|
||||||
|
_seed.text = state.config.seed.toString();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@@ -50,8 +54,11 @@ class _SortSettingsState extends State<SortSettings> {
|
|||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Text('数据数量(个数):'),
|
Text('数据数量(个数):'),
|
||||||
const SizedBox(width: 20,),
|
const SizedBox(
|
||||||
Expanded(child: TextField(
|
width: 20,
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: TextField(
|
||||||
controller: _count,
|
controller: _count,
|
||||||
)),
|
)),
|
||||||
],
|
],
|
||||||
@@ -59,8 +66,11 @@ class _SortSettingsState extends State<SortSettings> {
|
|||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Text('时间间隔(微秒):'),
|
Text('时间间隔(微秒):'),
|
||||||
const SizedBox(width: 20,),
|
const SizedBox(
|
||||||
Expanded(child: TextField(
|
width: 20,
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: TextField(
|
||||||
controller: _duration,
|
controller: _duration,
|
||||||
)),
|
)),
|
||||||
],
|
],
|
||||||
@@ -68,21 +78,29 @@ class _SortSettingsState extends State<SortSettings> {
|
|||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Text('随机种子:'),
|
Text('随机种子:'),
|
||||||
const SizedBox(width: 20,),
|
const SizedBox(
|
||||||
Expanded(child: TextField(
|
width: 20,
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: TextField(
|
||||||
controller: _seed,
|
controller: _seed,
|
||||||
)),
|
)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Spacer(),
|
Spacer(),
|
||||||
ElevatedButton(onPressed: (){
|
ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
sortConfig.value = SortConfig(int.parse(_count.text), Duration(
|
SortState state = SortStateScope.of(context);
|
||||||
microseconds: int.parse(_duration.text),
|
state.config =state.config.copyWith(
|
||||||
),int.parse(_seed.text),sortConfig.value.name);
|
count: int.parse(_count.text),
|
||||||
|
duration: Duration(
|
||||||
Navigator.of(context).pop();
|
microseconds: int.parse(_duration.text),
|
||||||
}, child: Text('确定设置'))
|
),
|
||||||
|
seed: int.parse(_seed.text)
|
||||||
|
);
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: Text('确定设置'))
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -19,23 +19,23 @@ class DataPainter extends CustomPainter{
|
|||||||
|
|
||||||
for(int i=0;i<data.length;i++){
|
for(int i=0;i<data.length;i++){
|
||||||
int value = data[i];
|
int value = data[i];
|
||||||
if (value < height * .10) {
|
if (value < 1000 * .10) {
|
||||||
paint.color = Colors.blue.shade100;
|
paint.color = Colors.blue.shade100;
|
||||||
} else if (value < height * .20) {
|
} else if (value < 1000 * .20) {
|
||||||
paint.color = Colors.blue.shade200;
|
paint.color = Colors.blue.shade200;
|
||||||
} else if (value < height * .30) {
|
} else if (value < 1000 * .30) {
|
||||||
paint.color = Colors.blue.shade300;
|
paint.color = Colors.blue.shade300;
|
||||||
} else if (value < height * .40) {
|
} else if (value < 1000 * .40) {
|
||||||
paint.color = Colors.blue.shade400;
|
paint.color = Colors.blue.shade400;
|
||||||
} else if (value < height * .50) {
|
} else if (value < 1000 * .50) {
|
||||||
paint.color = Colors.blue.shade500;
|
paint.color = Colors.blue.shade500;
|
||||||
} else if (value < height * .60) {
|
} else if (value < 1000 * .60) {
|
||||||
paint.color = Colors.blue.shade600;
|
paint.color = Colors.blue.shade600;
|
||||||
} else if (value < height * .70) {
|
} else if (value < 1000 * .70) {
|
||||||
paint.color = Colors.blue.shade700;
|
paint.color = Colors.blue.shade700;
|
||||||
} else if (value < height * .80) {
|
} else if (value < 1000 * .80) {
|
||||||
paint.color = Colors.blue.shade800;
|
paint.color = Colors.blue.shade800;
|
||||||
} else if (value < height * .90) {
|
} else if (value < 1000 * .90) {
|
||||||
paint.color = Colors.blue.shade900;
|
paint.color = Colors.blue.shade900;
|
||||||
} else {
|
} else {
|
||||||
paint.color = const Color(0xFF011E51);
|
paint.color = const Color(0xFF011E51);
|
||||||
@@ -44,7 +44,7 @@ class DataPainter extends CustomPainter{
|
|||||||
Offset(i * itemWidth+itemWidth/2, 0),
|
Offset(i * itemWidth+itemWidth/2, 0),
|
||||||
Offset(
|
Offset(
|
||||||
i * itemWidth+itemWidth/2,
|
i * itemWidth+itemWidth/2,
|
||||||
value.ceilToDouble(),
|
size.height*(value/1000),
|
||||||
),
|
),
|
||||||
paint);
|
paint);
|
||||||
}
|
}
|
||||||
|
|||||||
46
lib/v5/pages/sort/views/sort_bar.dart
Normal file
46
lib/v5/pages/sort/views/sort_bar.dart
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:iroute/components/components.dart';
|
||||||
|
|
||||||
|
import '../provider/state.dart';
|
||||||
|
import '../functions.dart';
|
||||||
|
import 'sort_button.dart';
|
||||||
|
|
||||||
|
class SortBar extends StatelessWidget {
|
||||||
|
const SortBar({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Row(
|
||||||
|
children: [
|
||||||
|
const SortButton(),
|
||||||
|
const SizedBox(width: 10,),
|
||||||
|
DropSelectableWidget(
|
||||||
|
fontSize: 12,
|
||||||
|
data: sortNameMap.values.toList(),
|
||||||
|
iconSize: 20,
|
||||||
|
height: 28,
|
||||||
|
width: 200,
|
||||||
|
disableColor: const Color(0xff1F425F),
|
||||||
|
onDropSelected: (int index) async {
|
||||||
|
SortState state = SortStateScope.of(context);
|
||||||
|
state.config =state.config.copyWith(
|
||||||
|
name: sortNameMap.keys.toList()[index]
|
||||||
|
);
|
||||||
|
// curveAnim = CurvedAnimation(
|
||||||
|
// parent: _ctrl, curve: maps.values.toList()[index]);
|
||||||
|
// _startAnim();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const SizedBox(width: 10,),
|
||||||
|
GestureDetector(
|
||||||
|
onTap: (){
|
||||||
|
Scaffold.of(context).openEndDrawer();
|
||||||
|
// showDialog(
|
||||||
|
// useRootNavigator: false,
|
||||||
|
// context: context, builder: (ctx)=>AlertDialog());
|
||||||
|
},
|
||||||
|
child: const Icon(Icons.settings))
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
40
lib/v5/pages/sort/views/sort_button.dart
Normal file
40
lib/v5/pages/sort/views/sort_button.dart
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../provider/state.dart';
|
||||||
|
|
||||||
|
class SortButton extends StatelessWidget {
|
||||||
|
const SortButton({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
SortState state = SortStateScope.of(context);
|
||||||
|
VoidCallback? action;
|
||||||
|
IconData icon;
|
||||||
|
Color color;
|
||||||
|
switch (state.status) {
|
||||||
|
case SortStatus.none:
|
||||||
|
icon = Icons.not_started_outlined;
|
||||||
|
color = Colors.green;
|
||||||
|
action = state.sort;
|
||||||
|
break;
|
||||||
|
case SortStatus.sorting:
|
||||||
|
icon = Icons.stop_circle_outlined;
|
||||||
|
color = Colors.grey;
|
||||||
|
action = null;
|
||||||
|
break;
|
||||||
|
case SortStatus.sorted:
|
||||||
|
icon = Icons.refresh;
|
||||||
|
color = Colors.black;
|
||||||
|
action = state.reset;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: action,
|
||||||
|
child: Icon(
|
||||||
|
icon,
|
||||||
|
color: color,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,228 +1,22 @@
|
|||||||
import 'dart:async';
|
|
||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../bloc/state.dart';
|
import '../provider/state.dart';
|
||||||
import '../functions.dart';
|
|
||||||
import '../bloc/sort_config.dart';
|
|
||||||
import 'data_painter.dart';
|
import 'data_painter.dart';
|
||||||
|
|
||||||
class SortPage extends StatefulWidget {
|
class SortPage extends StatelessWidget{
|
||||||
final Size size;
|
|
||||||
const SortPage({Key? key, required this.size}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<SortPage> createState() => _SortPageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _SortPageState extends State<SortPage> {
|
|
||||||
//存放随机数组
|
|
||||||
List<int> numbers = [];
|
|
||||||
|
|
||||||
//订阅流
|
|
||||||
StreamController<List<int>> streamController = StreamController();
|
|
||||||
|
|
||||||
String get currentSort => sortName.value;
|
|
||||||
|
|
||||||
//柱子的数量 -> 生成排序数组的长度
|
|
||||||
double sampleSize = 0;
|
|
||||||
|
|
||||||
//是否排序
|
|
||||||
bool isSorted = false;
|
|
||||||
|
|
||||||
//是否在排序中
|
|
||||||
bool isSorting = false;
|
|
||||||
|
|
||||||
|
|
||||||
reset() {
|
|
||||||
isSorted = false;
|
|
||||||
setSize(sortConfig.value.count);
|
|
||||||
streamController.add(numbers);
|
|
||||||
}
|
|
||||||
|
|
||||||
Duration getDuration() {
|
|
||||||
return sortConfig.value.duration;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkAndResetIfSorted() async {
|
|
||||||
if (isSorted) {
|
|
||||||
reset();
|
|
||||||
await Future.delayed(const Duration(milliseconds: 200));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sort() async {
|
|
||||||
setState(() {
|
|
||||||
isSorting = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
await checkAndResetIfSorted();
|
|
||||||
|
|
||||||
Stopwatch stopwatch = Stopwatch()..start();
|
|
||||||
|
|
||||||
SortFunction? sortFunction = sortFunctionMap[currentSort];
|
|
||||||
if(sortFunction!=null){
|
|
||||||
await sortFunction(numbers,(arr) async {
|
|
||||||
await Future.delayed(getDuration());
|
|
||||||
streamController.add(arr);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
stopwatch.stop();
|
|
||||||
print("Sorting completed in ${stopwatch.elapsed.inMilliseconds} ms.");
|
|
||||||
setState(() {
|
|
||||||
isSorting = false;
|
|
||||||
isSorted = true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
// reset();
|
|
||||||
print(widget.size);
|
|
||||||
setSize(sortConfig.value.count);
|
|
||||||
sortConfig.addListener(_onSortConfigChange);
|
|
||||||
sortName.addListener(reset);
|
|
||||||
}
|
|
||||||
|
|
||||||
Random random = Random();
|
|
||||||
void setSize(int count){
|
|
||||||
int s = count;
|
|
||||||
numbers.clear();
|
|
||||||
if(count==-1){
|
|
||||||
s = widget.size.width~/2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(sortConfig.value.seed!=-1){
|
|
||||||
random = Random(sortConfig.value.seed);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < s; i++) {
|
|
||||||
//随机往数组中填值
|
|
||||||
numbers.add(random.nextInt(widget.size.height.toInt()));
|
|
||||||
}
|
|
||||||
setState(() {});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
streamController.close();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
SortState state = SortStateScope.of(context);
|
||||||
List<int> numbers = SortStateScope.of(context).data;
|
List<int> numbers = state.data;
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
floatingActionButton: FloatingActionButton(
|
body: CustomPaint(
|
||||||
child: Icon(Icons.run_circle_outlined),
|
painter: DataPainter(data: numbers),
|
||||||
onPressed: (){
|
child: ConstrainedBox(constraints: BoxConstraints.expand()),
|
||||||
sort();
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
body: StreamBuilder<Object>(
|
|
||||||
initialData: numbers,
|
|
||||||
stream: streamController.stream,
|
|
||||||
builder: (context, snapshot) {
|
|
||||||
List<int> numbers = snapshot.data as List<int>;
|
|
||||||
return CustomPaint(
|
|
||||||
size: widget.size,
|
|
||||||
painter: DataPainter(data: numbers),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
// bottomNavigationBar: BottomAppBar(
|
|
||||||
// child: Row(
|
|
||||||
// mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
||||||
// children: <Widget>[
|
|
||||||
// ElevatedButton(
|
|
||||||
// onPressed: isSorting
|
|
||||||
// ? null
|
|
||||||
// : () {
|
|
||||||
// reset();
|
|
||||||
// setSort(currentSort);
|
|
||||||
// },
|
|
||||||
// child: const Text("重置")),
|
|
||||||
// ElevatedButton(
|
|
||||||
// onPressed: isSorting ? null : sort, child: const Text("开始排序")),
|
|
||||||
// ElevatedButton(
|
|
||||||
// onPressed: isSorting ? null : changeSpeed,
|
|
||||||
// child: Text(
|
|
||||||
// "${speed + 1}x",
|
|
||||||
// style: const TextStyle(fontSize: 20),
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
// ],
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onSortConfigChange() {
|
|
||||||
setSize(sortConfig.value.count);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class BarPainter extends CustomPainter {
|
|
||||||
//宽度
|
|
||||||
final double width;
|
|
||||||
final double height;
|
|
||||||
|
|
||||||
//高度(数组中对应的值)
|
|
||||||
final int value;
|
|
||||||
|
|
||||||
//位置索引
|
|
||||||
final int index;
|
|
||||||
|
|
||||||
BarPainter({required this.width, required this.height,required this.value, required this.index});
|
|
||||||
|
|
||||||
@override
|
|
||||||
void paint(Canvas canvas, Size size) {
|
|
||||||
Paint paint = Paint();
|
|
||||||
// double rate = value/height;
|
|
||||||
// print(rate);
|
|
||||||
// paint.color = Colors.blue.withOpacity(rate);
|
|
||||||
if (value < 500 * .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);
|
|
||||||
}
|
|
||||||
|
|
||||||
paint.strokeWidth = width;
|
|
||||||
paint.strokeCap = StrokeCap.round;
|
|
||||||
|
|
||||||
canvas.drawLine(
|
|
||||||
Offset(index * width+width/2, 0),
|
|
||||||
Offset(
|
|
||||||
index * width+width/2,
|
|
||||||
value.ceilToDouble(),
|
|
||||||
),
|
|
||||||
paint);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool shouldRepaint(covariant CustomPainter oldDelegate) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
|
|||||||
|
|
||||||
FlutterWindow window(project);
|
FlutterWindow window(project);
|
||||||
Win32Window::Point origin(10, 10);
|
Win32Window::Point origin(10, 10);
|
||||||
Win32Window::Size size(640, 360);
|
Win32Window::Size size(1600, 1200);
|
||||||
if (!window.Create(L"iroute", origin, size)) {
|
if (!window.Create(L"iroute", origin, size)) {
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user