Skip to content

Commit

Permalink
feat: add null safety support (chulwoo-park#33)
Browse files Browse the repository at this point in the history
* Add null safety support

* Fix process timeline showcase

* Remove misused non null codes
  • Loading branch information
areille authored Mar 27, 2021
1 parent c7d4c43 commit 91bb0bc
Show file tree
Hide file tree
Showing 19 changed files with 458 additions and 500 deletions.
17 changes: 8 additions & 9 deletions example/lib/component_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ComponentPage extends StatelessWidget {
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Colors.blue, Colors.lightBlueAccent[100]],
colors: [Colors.blue, Colors.lightBlueAccent.shade100],
),
),
),
Expand Down Expand Up @@ -348,8 +348,8 @@ class ComponentPage extends StatelessWidget {

class _ComponentRow extends TableRow {
_ComponentRow({
String name,
Widget item,
required String name,
required Widget item,
}) : super(
children: [
_ComponentName(name),
Expand All @@ -360,10 +360,9 @@ class _ComponentRow extends TableRow {

class _ComponentItem extends StatelessWidget {
const _ComponentItem({
Key key,
@required this.child,
}) : assert(child != null),
super(key: key);
Key? key,
required this.child,
}) : super(key: key);

final Widget child;

Expand All @@ -383,8 +382,8 @@ class _ComponentItem extends StatelessWidget {
class _ComponentName extends StatelessWidget {
const _ComponentName(
this.name, {
Key key,
}) : assert(name != null && name.length > 0),
Key? key,
}) : assert(name.length > 0),
super(key: key);

final String name;
Expand Down
14 changes: 7 additions & 7 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MyApp extends StatelessWidget {
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
onGenerateRoute: (settings) {
String path = Uri.tryParse(settings.name)?.path;
String? path = Uri.tryParse(settings.name!)?.path;
Widget child;
switch (path) {
case '/theme':
Expand Down Expand Up @@ -51,8 +51,8 @@ class MyApp extends StatelessWidget {

class HomePage extends StatefulWidget {
HomePage({
Key key,
@required this.child,
Key? key,
required this.child,
}) : super(key: key);

final Widget child;
Expand All @@ -77,7 +77,7 @@ class _HomePageState extends State<HomePage> {
return WillPopScope(
onWillPop: () async {
if (_navigatorKey.currentState?.canPop() ?? false) {
_navigatorKey.currentState.maybePop();
_navigatorKey.currentState?.maybePop();
return false;
} else {
return true;
Expand Down Expand Up @@ -152,13 +152,13 @@ class ExamplePage extends StatelessWidget {

class _NavigationCard extends StatelessWidget {
const _NavigationCard({
Key key,
@required this.name,
Key? key,
required this.name,
this.navigationBuilder,
}) : super(key: key);

final String name;
final NavigateWidgetBuilder navigationBuilder;
final NavigateWidgetBuilder? navigationBuilder;

@override
Widget build(BuildContext context) {
Expand Down
58 changes: 26 additions & 32 deletions example/lib/showcase/package_delivery_tracking.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ class PackageDeliveryTrackingPage extends StatelessWidget {

class _OrderTitle extends StatelessWidget {
const _OrderTitle({
Key key,
@required this.orderInfo,
}) : assert(orderInfo != null),
super(key: key);
Key? key,
required this.orderInfo,
}) : super(key: key);

final _OrderInfo orderInfo;

Expand Down Expand Up @@ -78,7 +77,7 @@ class _OrderTitle extends StatelessWidget {

class _InnerTimeline extends StatelessWidget {
const _InnerTimeline({
@required this.messages,
required this.messages,
});

final List<_DeliveryMessage> messages;
Expand Down Expand Up @@ -128,9 +127,8 @@ class _InnerTimeline extends StatelessWidget {
}

class _DeliveryProcesses extends StatelessWidget {
const _DeliveryProcesses({Key key, @required this.processes})
: assert(processes != null),
super(key: key);
const _DeliveryProcesses({Key? key, required this.processes})
: super(key: key);

final List<_DeliveryProcess> processes;
@override
Expand Down Expand Up @@ -204,31 +202,27 @@ class _DeliveryProcesses extends StatelessWidget {
}

class _OnTimeBar extends StatelessWidget {
const _OnTimeBar({Key key, @required this.driver})
: assert(driver != null),
super(key: key);
const _OnTimeBar({Key? key, required this.driver}) : super(key: key);

final _DriverInfo driver;

@override
Widget build(BuildContext context) {
return Row(
children: [
Builder(
builder: (context) => MaterialButton(
onPressed: () {
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text('On-time!'),
),
);
},
elevation: 0,
shape: StadiumBorder(),
color: Color(0xff66c97f),
textColor: Colors.white,
child: Text('On-time'),
),
MaterialButton(
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('On-time!'),
),
);
},
elevation: 0,
shape: StadiumBorder(),
color: Color(0xff66c97f),
textColor: Colors.white,
child: Text('On-time'),
),
Spacer(),
Text(
Expand Down Expand Up @@ -283,10 +277,10 @@ _OrderInfo _data(int id) => _OrderInfo(

class _OrderInfo {
const _OrderInfo({
@required this.id,
@required this.date,
@required this.driverInfo,
@required this.deliveryProcesses,
required this.id,
required this.date,
required this.driverInfo,
required this.deliveryProcesses,
});

final int id;
Expand All @@ -297,8 +291,8 @@ class _OrderInfo {

class _DriverInfo {
const _DriverInfo({
@required this.name,
this.thumbnailUrl,
required this.name,
required this.thumbnailUrl,
});

final String name;
Expand Down
8 changes: 4 additions & 4 deletions example/lib/showcase/process_timeline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ class _ProcessTimelinePageState extends State<ProcessTimelinePage> {
if (index == _processIndex) {
final prevColor = getColor(index - 1);
final color = getColor(index);
var gradientColors;
List<Color> gradientColors;
if (type == ConnectorType.start) {
gradientColors = [Color.lerp(prevColor, color, 0.5), color];
gradientColors = [Color.lerp(prevColor, color, 0.5)!, color];
} else {
gradientColors = [
prevColor,
Color.lerp(prevColor, color, 0.5)
Color.lerp(prevColor, color, 0.5)!
];
}
return DecoratedLineConnector(
Expand Down Expand Up @@ -179,7 +179,7 @@ class _ProcessTimelinePageState extends State<ProcessTimelinePage> {
/// TODO: Bezier curve into package component
class _BezierPainter extends CustomPainter {
const _BezierPainter({
@required this.color,
required this.color,
this.drawStart = true,
this.drawEnd = true,
});
Expand Down
12 changes: 6 additions & 6 deletions example/lib/showcase_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ class ShowcasePage extends StatelessWidget {

class _ShowcaseCard extends StatelessWidget {
const _ShowcaseCard({
Key key,
@required this.navigationBuilder,
@required this.image,
@required this.title,
@required this.designer,
@required this.url,
Key? key,
required this.navigationBuilder,
required this.image,
required this.title,
required this.designer,
required this.url,
}) : super(key: key);

final String image;
Expand Down
46 changes: 23 additions & 23 deletions example/lib/theme_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class _ThemePageState extends State<ThemePage> {
'ORANGE': Colors.orange,
};

TimelineThemeData _theme;
late TimelineThemeData _theme;

@override
void initState() {
Expand Down Expand Up @@ -83,7 +83,7 @@ class _ThemePageState extends State<ThemePage> {
'Horizontal': Axis.horizontal,
},
value: _theme.direction,
onChanged: (axis) {
onChanged: (Axis? axis) {
if (_theme.direction != axis) {
setState(() {
_updateTheme(_theme.copyWith(direction: axis));
Expand All @@ -95,7 +95,7 @@ class _ThemePageState extends State<ThemePage> {
title: 'Color',
items: _themeColors,
value: _theme.color,
onChanged: (color) {
onChanged: (Color? color) {
_updateTheme(_theme.copyWith(color: color));
},
),
Expand Down Expand Up @@ -142,7 +142,7 @@ class _ThemePageState extends State<ThemePage> {
'IndicatorTheme',
style: Theme.of(context).textTheme.headline6,
),
_ThemeDropdown(
_ThemeDropdown<Color?>(
title: 'Color',
items: _themeColors,
value: _theme.indicatorTheme.color,
Expand All @@ -158,7 +158,7 @@ class _ThemePageState extends State<ThemePage> {
SizedBox(height: 10.0),
_ThemeSlider(
title: 'Position',
value: _theme.indicatorTheme.position,
value: _theme.indicatorTheme.position ?? 0,
onChanged: (position) {
_updateTheme(
_theme.copyWith(
Expand All @@ -170,7 +170,7 @@ class _ThemePageState extends State<ThemePage> {
),
_ThemeSlider(
title: 'Size',
value: _theme.indicatorTheme.size,
value: _theme.indicatorTheme.size ?? 0,
max: 100.0,
onChanged: (size) {
_updateTheme(
Expand All @@ -194,7 +194,7 @@ class _ThemePageState extends State<ThemePage> {
'ConnectorTheme',
style: Theme.of(context).textTheme.headline6,
),
_ThemeDropdown(
_ThemeDropdown<Color?>(
title: 'Color',
items: _themeColors,
value: _theme.connectorTheme.color,
Expand All @@ -210,7 +210,7 @@ class _ThemePageState extends State<ThemePage> {
SizedBox(height: 10.0),
_ThemeSlider(
title: 'Space',
value: _theme.connectorTheme.space,
value: _theme.connectorTheme.space ?? 0,
max: 100,
onChanged: (space) {
_updateTheme(
Expand All @@ -223,7 +223,7 @@ class _ThemePageState extends State<ThemePage> {
),
_ThemeSlider(
title: 'Indent',
value: _theme.connectorTheme.indent,
value: _theme.connectorTheme.indent ?? 0,
max: 22,
onChanged: (indent) {
_updateTheme(
Expand All @@ -236,7 +236,7 @@ class _ThemePageState extends State<ThemePage> {
),
_ThemeSlider(
title: 'Thickness',
value: _theme.connectorTheme.thickness,
value: _theme.connectorTheme.thickness ?? 0,
max: 100,
onChanged: (thickness) {
_updateTheme(
Expand Down Expand Up @@ -287,17 +287,17 @@ class _ThemePageState extends State<ThemePage> {

class _ThemeDropdown<T> extends StatelessWidget {
const _ThemeDropdown({
Key key,
@required this.title,
@required this.items,
@required this.value,
@required this.onChanged,
Key? key,
required this.title,
required this.items,
required this.value,
required this.onChanged,
}) : super(key: key);

final String title;
final Map<String, T> items;
final T value;
final ValueChanged<T> onChanged;
final ValueChanged<T?> onChanged;

@override
Widget build(BuildContext context) {
Expand All @@ -322,15 +322,15 @@ class _ThemeDropdown<T> extends StatelessWidget {

class _ThemeSlider extends StatelessWidget {
const _ThemeSlider({
Key key,
@required this.title,
@required this.value,
@required this.onChanged,
Key? key,
required this.title,
required this.value,
required this.onChanged,
this.max = 1.0,
}) : super(key: key);

final String title;
final double value;
final double? value;
final ValueChanged<double> onChanged;
final double max;

Expand All @@ -339,8 +339,8 @@ class _ThemeSlider extends StatelessWidget {
var label;
if (value == null) {
label = '';
} else if (value > 1) {
label = value.toInt().toString();
} else if (value! > 1) {
label = value!.toInt().toString();
} else {
label = value.toString();
}
Expand Down
Loading

0 comments on commit 91bb0bc

Please sign in to comment.