Reduce code duplication by introducing an OnBoardingButton

This commit is contained in:
Vishesh Handa
2019-01-16 22:24:48 +01:00
parent 0a76ab58f8
commit 65480a2aa0
2 changed files with 74 additions and 62 deletions

View File

@ -77,19 +77,55 @@ class OnBoardingGitUrlState extends State<OnBoardingGitUrl> {
child: inputForm, child: inputForm,
), ),
SizedBox(height: 8.0), SizedBox(height: 8.0),
SizedBox( OnBoardingButton(
width: double.infinity, text: "Next",
child: RaisedButton( onPressed: formSubmitted,
child: Text( ),
"Next",
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.button,
),
color: Theme.of(context).primaryColor,
onPressed: formSubmitted,
),
)
], ],
); );
} }
} }
class OnBoardingButton extends StatelessWidget {
final Function onPressed;
final String text;
final String iconUrl;
OnBoardingButton({
@required this.text,
@required this.onPressed,
this.iconUrl,
});
@override
Widget build(BuildContext context) {
if (iconUrl == null) {
return SizedBox(
width: double.infinity,
child: RaisedButton(
child: Text(
text,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.button,
),
color: Theme.of(context).primaryColor,
onPressed: onPressed,
),
);
} else {
return SizedBox(
width: double.infinity,
child: RaisedButton.icon(
label: Text(
text,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.button,
),
icon: Image.asset(iconUrl, width: 32, height: 32),
color: Theme.of(context).primaryColor,
onPressed: onPressed,
),
);
}
}
}

View File

@ -336,58 +336,34 @@ class OnBoardingCreateRepo extends StatelessWidget {
style: Theme.of(context).textTheme.headline, style: Theme.of(context).textTheme.headline,
), ),
SizedBox(height: 16.0), SizedBox(height: 16.0),
SizedBox( OnBoardingButton(
width: double.infinity, text: "GitHub",
child: RaisedButton.icon( iconUrl: 'assets/icon/github-icon.png',
label: Text( onPressed: () async {
"GitHub", try {
textAlign: TextAlign.center, await launch("https://github.com/new");
style: Theme.of(context).textTheme.button, } catch (err, stack) {
), // FIXME: Error handling?
icon: Image.asset( print(err);
'assets/icon/github-icon.png', print(stack);
width: 32, }
height: 32, onDone();
), },
color: Theme.of(context).primaryColor,
onPressed: () async {
try {
await launch("https://github.com/new");
} catch (err, stack) {
// FIXME: Error handling?
print(err);
print(stack);
}
onDone();
},
),
), ),
SizedBox(height: 8.0), SizedBox(height: 8.0),
SizedBox( OnBoardingButton(
width: double.infinity, text: "GitLab",
child: RaisedButton.icon( iconUrl: 'assets/icon/gitlab-icon.png',
label: Text( onPressed: () async {
"GitLab", try {
textAlign: TextAlign.center, await launch("https://gitlab.com/projects/new");
style: Theme.of(context).textTheme.button, } catch (err, stack) {
), // FIXME: Error handling?
icon: Image.asset( print(err);
'assets/icon/gitlab-icon.png', print(stack);
width: 32, }
height: 32, onDone();
), },
color: Theme.of(context).primaryColor,
onPressed: () async {
try {
await launch("https://gitlab.com/projects/new");
} catch (err, stack) {
// FIXME: Error handling?
print(err);
print(stack);
}
onDone();
},
),
), ),
], ],
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,