Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F/fix #71 #76

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ class _ActionSheetEntryPageState extends State<ActionSheetEntryPage> {
// 用于控制timer只加载一次
var started = false;
// 计时器
var periodTimer;
Timer periodTimer;
List<BrnCommonActionSheetItem> actions = List();
actions.add(BrnCommonActionSheetItem(
'倒计时:$countdown',
Expand Down Expand Up @@ -369,7 +369,7 @@ class _ActionSheetEntryPageState extends State<ActionSheetEntryPage> {
actions[0].desc = '倒计时:$times';
});
} else if (countdown == 0) {
periodTimer.onCancel();
periodTimer.cancel();
}
});
}
Expand All @@ -380,15 +380,15 @@ class _ActionSheetEntryPageState extends State<ActionSheetEntryPage> {
BrnCommonActionSheetItem actionEle,
) {
// 点击后立即停止计时
periodTimer.onCancel();
periodTimer.cancel();
var title = actionEle.title;
BrnToast.show("title: $title, index: $index", context);
},
);
});
// then用来在pop折后停止timer,如果不需要在pop后进行操作,不需要使用then
}).then((value) {
periodTimer.onCancel();
periodTimer.cancel();
});
}

Expand Down
167 changes: 140 additions & 27 deletions example/lib/sample/components/step/brn_horizontal_step_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,170 @@ import 'package:flutter/material.dart';
class BrnHorizontalStepExamplePage extends StatefulWidget {
final String title;

BrnHorizontalStepExamplePage({this.title});
const BrnHorizontalStepExamplePage({Key key, this.title}) : super(key: key);

@override
State<StatefulWidget> createState() {
return BrnHorizontalStepExamplePageState();
}
}

class BrnHorizontalStepExamplePageState extends State<BrnHorizontalStepExamplePage> {
class BrnHorizontalStepExamplePageState
extends State<BrnHorizontalStepExamplePage> {
int _index;
BrnHorizontalStepsManager _stepsManager = BrnHorizontalStepsManager();
double sliderValue = 2;
BrnStepsController _controller;
ValueNotifier<double> valueNotifier;

@override
void initState() {
_index = 1;
super.initState();
_index = 0;
_controller = BrnStepsController(currentIndex: _index);
valueNotifier = ValueNotifier(sliderValue);
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: BrnAppBar(
title: widget.title,
actions: controlSteps(context),
),
body: _stepsManager.buildSteps(currentIndex: _index, isCompleted: false, steps: <BrunoStep>[
BrunoStep(
stepContentText: "文案步骤",
appBar: BrnAppBar(title: widget.title),
body: Column(
children: [
BrnHorizontalStep(
controller: _controller,
valueNotifier: valueNotifier,
),
BrunoStep(
stepContentText: "文案步骤",
const Text('步骤个数:'),
SliderWidget(
initValue: sliderValue,
valueNotifier: valueNotifier,
),
BrunoStep(
stepContentText: "文案步骤",
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
child: const Text('上一步'),
onPressed: () {
_controller.backStep();
},
),
ElevatedButton(
child: const Text('下一步'),
onPressed: () {
_controller.forwardStep();
},
),
],
),
BrunoStep(
stepContentText: "文案步骤",
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
child: const Text('跳至第3步'),
onPressed: () {
_controller.setCurrentIndex(2);
},
),
ElevatedButton(
child: const Text('完成'),
onPressed: () {
_controller.setCompleted();
},
),
],
),
]));
],
),
);
}
}

class SliderWidget extends StatefulWidget {
const SliderWidget({
Key key,
@required this.initValue,
@required this.valueNotifier,
}) : super(key: key);
final double initValue;
final ValueNotifier<double> valueNotifier;

@override
_SliderWidgetState createState() => _SliderWidgetState();
}

class _SliderWidgetState extends State<SliderWidget> {
double sliderValue;

@override
void initState() {
super.initState();
sliderValue = widget.initValue;
}

@override
Widget build(BuildContext context) {
return Slider(
value: sliderValue,
min: 2,
max: 5,
divisions: 3,
onChanged: (value) {
setState(() {
sliderValue = value;
widget.valueNotifier.value = value;
});
},
);
}
}

List<Widget> controlSteps(BuildContext context) {
List<Widget> result = List<Widget>();
class BrnHorizontalStep extends StatefulWidget {
const BrnHorizontalStep({
Key key,
@required this.controller,
@required this.valueNotifier,
}) : super(key: key);
final BrnStepsController controller;
final ValueNotifier<double> valueNotifier;

result.add(BrnTextAction("上一步", iconPressed: () {
_stepsManager.backStep();
}));
@override
_BrnHorizontalStepsState createState() => _BrnHorizontalStepsState();
}

class _BrnHorizontalStepsState extends State<BrnHorizontalStep> {
List<BrunoStep> brunoSteps() {
final List<BrunoStep> _list = [];
final int value = widget.valueNotifier.value.toInt();
for (int i = 0; i < value; i++) {
_list.add(BrunoStep(stepContentText: ('第${i + 1}步')));
}
return _list;
}

void _onChange() {
setState(() {
brunoSteps();
widget.controller.setCurrentIndex(0);
});
}

@override
void initState() {
super.initState();
widget.valueNotifier.addListener(_onChange);
}

@override
void dispose() {
widget.valueNotifier.removeListener(_onChange);
super.dispose();
}

result.add(BrnTextAction("下一步", iconPressed: () {
_stepsManager.forwardStep();
}));
return result;
@override
Widget build(BuildContext context) {
return BrnHorizontalSteps(
steps: brunoSteps(),
controller: widget.controller,
);
}
}
Loading