Skip to content

Commit

Permalink
fix: minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
stonega committed Mar 8, 2022
1 parent 524715d commit a5cada2
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 42 deletions.
10 changes: 5 additions & 5 deletions lib/api/jenkins_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class JenkinsApi {
await HiveBox.saveUsername(userInfo['fullName']);
}

static logout() {
HiveBox.saveToken('');
HiveBox.saveBaseUrl('');
HiveBox.saveJobs([]);
HiveBox.saveBuildTasks([]);
static logout() async {
await HiveBox.saveToken('');
await HiveBox.saveBaseUrl('');
await HiveBox.saveJobs([]);
await HiveBox.saveBuildTasks([]);
}

static Future<List<JobGroup>> getAllJobs() async {
Expand Down
6 changes: 3 additions & 3 deletions lib/view/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class HomeView extends ConsumerWidget {
color: context.primaryColorDark,
),
IconButton(
onPressed: () => _logout(context),
onPressed: () async => await _logout(context),
splashRadius: 20,
icon: Icon(
LineIcons.shareSquare,
Expand All @@ -167,8 +167,8 @@ class HomeView extends ConsumerWidget {
);
}

void _logout(BuildContext context) {
JenkinsApi.logout();
Future _logout(BuildContext context) async {
await JenkinsApi.logout();
context.push('/');
}
}
11 changes: 11 additions & 0 deletions lib/view/login/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class _LoginPageState extends ConsumerState<LoginPage> {
late TextEditingController _urlController;
late PageController _pageViewController;
late String _error;
bool _loading = false;

@override
void initState() {
Expand Down Expand Up @@ -164,6 +165,7 @@ class _LoginPageState extends ConsumerState<LoginPage> {
child: SizedBox(
height: 50,
child: CustomButton(
loading: _loading,
onPressed: _submit,
child: const Text(
'Get Started',
Expand Down Expand Up @@ -196,11 +198,20 @@ class _LoginPageState extends ConsumerState<LoginPage> {
setState(() => _error = 'Username can not be empty');
return;
}
setState(() {
_loading = true;
});
try {
await JenkinsApi.login(username, token, HiveBox.getBaseUrl());
context.go('/');
} catch (e) {
context.toast('Auth failed');
} finally {
if (mounted) {
setState(() {
_loading = false;
});
}
}
}

Expand Down
35 changes: 35 additions & 0 deletions lib/view/settings/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:jenkins_board/provider/app_state_provider.dart';
import 'package:jenkins_board/utils/extensions.dart';
import 'package:jenkins_board/utils/helper.dart';
import 'package:jenkins_board/widgets/setting_wrapper.dart';
import 'package:line_icons/line_icons.dart';

const githubUrl = "https://github.com/stonega/jenkins-board";

class SettingsPage extends ConsumerWidget {
const SettingsPage({Key? key}) : super(key: key);
Expand Down Expand Up @@ -49,6 +53,37 @@ class SettingsPage extends ConsumerWidget {
const Text('中文')
],
),
const SizedBox(
height: 20,
),
Text(
'About',
style: context.headline5,
),
const SizedBox(
height: 20,
),
Text('Jenkins Board',
style:
context.bodyText1.copyWith(color: context.accentColor)),
const SizedBox(
height: 10,
),
GestureDetector(
onTap: () {
Helper.launchURL(githubUrl);
context.toast('Opened in browser');
},
child: Row(
children: const [
Icon(
LineIcons.github,
),
SizedBox(width: 10),
Text('GitHub')
],
),
)
],
),
),
Expand Down
87 changes: 53 additions & 34 deletions lib/widgets/custom_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,59 @@ class CustomButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ElevatedButton(
style: ButtonStyle(
enableFeedback: false,
elevation: MaterialStateProperty.resolveWith<double>((states) {
return 0;
}),
padding: MaterialStateProperty.all(
const EdgeInsets.symmetric(vertical: 15)),
overlayColor: MaterialStateProperty.all(Colors.transparent),
backgroundColor: MaterialStateProperty.resolveWith<Color>(
(states) {
if (states.contains(MaterialState.disabled)) {
return const Color(0xffececec);
} else if (states.contains(MaterialState.pressed)) {
return backgroundColor?.withOpacity(0.8) ??
context.accentColor.withOpacity(0.8);
}
return backgroundColor ?? context.accentColor;
},
),
foregroundColor: MaterialStateProperty.resolveWith<Color>(
(states) {
if (states.contains(MaterialState.disabled)) {
return Colors.black;
}
return Colors.white;
},
),
animationDuration: Duration.zero,
shape: MaterialStateProperty.all<OutlinedBorder>(
RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
style: ButtonStyle(
enableFeedback: false,
elevation: MaterialStateProperty.resolveWith<double>((states) {
return 0;
}),
padding:
MaterialStateProperty.all(const EdgeInsets.symmetric(vertical: 15)),
overlayColor: MaterialStateProperty.all(Colors.transparent),
backgroundColor: MaterialStateProperty.resolveWith<Color>(
(states) {
if (states.contains(MaterialState.disabled)) {
return const Color(0xffececec);
} else if (states.contains(MaterialState.pressed)) {
return backgroundColor?.withOpacity(0.8) ??
context.accentColor.withOpacity(0.8);
}
return backgroundColor ?? context.accentColor;
},
),
onPressed: onPressed,
clipBehavior: Clip.hardEdge,
child: child);
foregroundColor: MaterialStateProperty.resolveWith<Color>(
(states) {
if (states.contains(MaterialState.disabled)) {
return Colors.black;
}
return Colors.white;
},
),
animationDuration: Duration.zero,
shape: MaterialStateProperty.all<OutlinedBorder>(
RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
),
onPressed: onPressed,
clipBehavior: Clip.hardEdge,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (child != null) child!,
if (loading)
const Padding(
padding: EdgeInsets.only(left: 8.0),
child: SizedBox(
height: 14,
width: 14,
child: Center(
child: CircularProgressIndicator(
strokeWidth: 2,
),
),
),
)
],
),
);
}
}

0 comments on commit a5cada2

Please sign in to comment.