-
Notifications
You must be signed in to change notification settings - Fork 506
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
migrate brn_horizontal_steps、brn_step_line to null safety #89
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
174 changes: 144 additions & 30 deletions
174
example/lib/sample/components/step/brn_horizontal_step_example.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,176 @@ | ||
// @dart=2.9 | ||
|
||
import 'package:bruno/bruno.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class BrnHorizontalStepExamplePage extends StatefulWidget { | ||
final String title; | ||
|
||
BrnHorizontalStepExamplePage({this.title}); | ||
const BrnHorizontalStepExamplePage({Key? key, required this.title}) | ||
: super(key: key); | ||
|
||
@override | ||
State<StatefulWidget> createState() { | ||
return BrnHorizontalStepExamplePageState(); | ||
} | ||
} | ||
|
||
class BrnHorizontalStepExamplePageState extends State<BrnHorizontalStepExamplePage> { | ||
int _index; | ||
BrnHorizontalStepsManager _stepsManager = BrnHorizontalStepsManager(); | ||
class BrnHorizontalStepExamplePageState | ||
extends State<BrnHorizontalStepExamplePage> { | ||
late int _index; | ||
double sliderValue = 2; | ||
late BrnStepsController _controller; | ||
late 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: [ | ||
SliverBrnHorizontalStep( | ||
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(); | ||
}, | ||
), | ||
], | ||
), | ||
])); | ||
], | ||
), | ||
); | ||
} | ||
} | ||
|
||
/// 自定义 widget | ||
class SliderWidget extends StatefulWidget { | ||
const SliderWidget({ | ||
Key? key, | ||
required this.initValue, | ||
required this.valueNotifier, | ||
}) : super(key: key); | ||
final double initValue; | ||
final ValueNotifier<double> valueNotifier; | ||
|
||
List<Widget> controlSteps(BuildContext context) { | ||
List<Widget> result = List<Widget>(); | ||
@override | ||
_SliderWidgetState createState() => _SliderWidgetState(); | ||
} | ||
|
||
result.add(BrnTextAction("上一步", iconPressed: () { | ||
_stepsManager.backStep(); | ||
})); | ||
class _SliderWidgetState extends State<SliderWidget> { | ||
late double sliderValue; | ||
|
||
result.add(BrnTextAction("下一步", iconPressed: () { | ||
_stepsManager.forwardStep(); | ||
})); | ||
return result; | ||
@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; | ||
}); | ||
}, | ||
); | ||
} | ||
} | ||
|
||
/// 自定义 widget | ||
class SliverBrnHorizontalStep extends StatefulWidget { | ||
const SliverBrnHorizontalStep({ | ||
Key? key, | ||
required this.controller, | ||
required this.valueNotifier, | ||
}) : super(key: key); | ||
final BrnStepsController controller; | ||
final ValueNotifier<double> valueNotifier; | ||
|
||
@override | ||
_SliverBrnHorizontalStepsState createState() => _SliverBrnHorizontalStepsState(); | ||
} | ||
|
||
class _SliverBrnHorizontalStepsState extends State<SliverBrnHorizontalStep> { | ||
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(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return BrnHorizontalSteps( | ||
steps: brunoSteps(), | ||
controller: widget.controller, | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mark 一下,后面修改实现