Skip to content

Commit 43f3ebf

Browse files
add play, stop, reset controls for sorting widgets
1 parent 920dd44 commit 43f3ebf

File tree

1 file changed

+68
-35
lines changed

1 file changed

+68
-35
lines changed

lib/features/sorting/view/sorting_page.dart

Lines changed: 68 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
import 'package:algorithm_visualizer/core/resources/strings_manager.dart';
2+
import 'package:algorithm_visualizer/core/resources/theme_manager.dart';
3+
import 'package:algorithm_visualizer/core/widgets/adaptive/text/adaptive_text.dart';
4+
import 'package:algorithm_visualizer/core/widgets/custom_widgets/custom_rounded_elevated_button.dart';
15
import 'package:algorithm_visualizer/features/sorting/view_model/sorting_notifier.dart';
26
import 'package:flutter/material.dart';
37
import 'package:flutter_riverpod/flutter_riverpod.dart';
48
part '../widgets/sorting_app_bar.dart';
9+
part '../widgets/control_buttons.dart';
510

611
final _notifierProvider = StateNotifierProvider<SortingNotifier, SortingNotifierState>(
712
(ref) => SortingNotifier(),
@@ -15,44 +20,72 @@ class SortingPage extends StatelessWidget {
1520
return Scaffold(
1621
appBar: AppBar(
1722
elevation: 1,
18-
title: Consumer(builder: (context, ref, _) {
19-
return InkWell(
20-
onTap: () {
21-
ref.read(_notifierProvider.notifier).bubbleSort();
22-
},
23-
child: const Text("Sort"),
24-
);
25-
}),
23+
title: Consumer(
24+
builder: (context, ref, _) {
25+
return InkWell(
26+
onTap: () {
27+
ref.read(_notifierProvider.notifier).bubbleSort();
28+
},
29+
child: const Text("Sort"),
30+
);
31+
},
32+
),
33+
),
34+
body: const Stack(
35+
alignment: AlignmentDirectional.bottomCenter,
36+
children: [
37+
Align(alignment: AlignmentDirectional.topCenter, child: _BuildList()),
38+
_InteractionButton(),
39+
],
2640
),
27-
body: Consumer(builder: (context, ref, _) {
28-
final items = ref.watch(_notifierProvider).list;
41+
);
42+
}
43+
}
2944

30-
return Padding(
31-
padding: const EdgeInsets.only(top: 15),
32-
child: SizedBox(
33-
height: SortingNotifier.maxListItemHeight*1.2,
34-
width: double.infinity,
35-
child: Stack(
36-
alignment: AlignmentDirectional.bottomCenter,
37-
children: List.generate(
38-
items.length,
39-
(index) {
40-
final item = items[index];
41-
final position =
42-
ref.watch(_notifierProvider.select((state) => state.positions[item.id]!));
43-
return AnimatedPositioned(
44-
key: ValueKey(item.id),
45-
left: position.dx,
46-
bottom: position.dy,
47-
duration: SortingNotifier.swipeDuration,
48-
child: _BuildItem(item: item),
49-
);
50-
},
51-
),
52-
),
45+
class _InteractionButton extends ConsumerWidget {
46+
const _InteractionButton();
47+
48+
@override
49+
Widget build(BuildContext context, ref) {
50+
return const Column(
51+
mainAxisSize: MainAxisSize.min,
52+
children: [
53+
_ControlButtons(),
54+
],
55+
);
56+
}
57+
}
58+
59+
class _BuildList extends ConsumerWidget {
60+
const _BuildList();
61+
62+
@override
63+
Widget build(BuildContext context, ref) {
64+
final items = ref.watch(_notifierProvider).list;
65+
66+
return Padding(
67+
padding: const EdgeInsets.only(top: 15),
68+
child: SizedBox(
69+
height: SortingNotifier.maxListItemHeight * 1.2,
70+
width: double.infinity,
71+
child: Stack(
72+
alignment: AlignmentDirectional.bottomCenter,
73+
children: List.generate(
74+
items.length,
75+
(index) {
76+
final item = items[index];
77+
final position = ref.watch(_notifierProvider.select((state) => state.positions[item.id]!));
78+
return AnimatedPositioned(
79+
key: ValueKey(item.id),
80+
left: position.dx,
81+
bottom: position.dy,
82+
duration: SortingNotifier.swipeDuration,
83+
child: _BuildItem(item: item),
84+
);
85+
},
5386
),
54-
);
55-
}),
87+
),
88+
),
5689
);
5790
}
5891
}

0 commit comments

Comments
 (0)