Skip to content

Commit

Permalink
fix: popover creah issue
Browse files Browse the repository at this point in the history
  • Loading branch information
stonega committed Jun 11, 2022
1 parent 7dcd30d commit f840f49
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 169 deletions.
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ include: package:flutter_lints/flutter.yaml

linter:
rules:
use_build_context_synchronously: false

analyzer:
exclude:
Expand Down
101 changes: 3 additions & 98 deletions lib/view/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:jenkins_board/api/jenkins_api.dart';
import 'package:jenkins_board/provider/jobs_provider.dart';
import 'package:jenkins_board/storage/hive_box.dart';
import 'package:jenkins_board/utils/extensions.dart';
import 'package:jenkins_board/view/settings/build_detail.dart';
import 'package:jenkins_board/view/settings/build_task.dart';
import 'package:jenkins_board/view/settings/choose_jobs.dart';
import 'package:jenkins_board/view/settings/settings.dart';
import 'package:jenkins_board/widgets/build_task_button.dart';
import 'package:jenkins_board/widgets/custom_button.dart';
import 'package:jenkins_board/widgets/job_panel.dart';
import 'package:line_icons/line_icons.dart';
import 'package:jenkins_board/widgets/topbar.dart';
import 'package:reorderables/reorderables.dart';

enum SettingType { choose_jobs, settings, build_detail, build_tasks, undefined }
Expand Down Expand Up @@ -67,95 +61,11 @@ class HomeView extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final jobs = ref.watch(jobsProvider);
final username = HiveBox.getUsername();
return ListView(
children: [
const Topbar(),
Padding(
padding: const EdgeInsets.fromLTRB(30, 30, 30, 20),
child: Row(
children: [
Text('Hi $username', style: context.headline4),
const SizedBox(
width: 20,
),
CustomButton(
onPressed: () {
context.go('/home/choose_jobs');
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Row(
children: [
Text(context.S.addJob),
const Icon(
LineIcons.plusCircle,
size: 25,
),
],
),
),
),
const Spacer(),
const BuildTasksButton(),
const SizedBox(
width: 20,
),
Container(
decoration: BoxDecoration(
color: context.primaryColorLight,
borderRadius: BorderRadius.circular(100),
),
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Row(
children: [
IconButton(
onPressed: ref.read(jobsProvider.notifier).refresh,
splashRadius: 20,
icon: Icon(
LineIcons.alternateRedo,
color: context.primaryColorDark,
size: 20,
),
tooltip: context.S.refresh,
),
Container(
width: 2,
height: 20,
color: context.primaryColorDark,
),
IconButton(
onPressed: () {
context.go('/home/settings');
},
splashRadius: 20,
icon: Icon(
LineIcons.cog,
color: context.primaryColorDark,
),
tooltip: context.S.settings,
),
Container(
width: 2,
height: 20,
color: context.primaryColorDark,
),
IconButton(
onPressed: () async => await _logout(context),
splashRadius: 20,
icon: Icon(
LineIcons.shareSquare,
color: context.primaryColorDark,
),
tooltip: context.S.logout,
),
],
),
),
],
),
),
Padding(
padding: const EdgeInsets.fromLTRB(15, 15, 30, 15),
padding: const EdgeInsets.fromLTRB(15, 15, 0, 15),
child: ReorderableWrap(
onReorder: ref.read(jobsProvider.notifier).reOrder,
spacing: 20,
Expand All @@ -166,9 +76,4 @@ class HomeView extends ConsumerWidget {
],
);
}

Future _logout(BuildContext context) async {
await JenkinsApi.logout();
context.push('/');
}
}
7 changes: 3 additions & 4 deletions lib/widgets/custom_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class CustomButton extends StatelessWidget {
Widget build(BuildContext context) {
return ElevatedButton(
style: ButtonStyle(
enableFeedback: false,
elevation: MaterialStateProperty.resolveWith<double>((states) {
return 0;
}),
Expand All @@ -45,8 +44,8 @@ class CustomButton extends StatelessWidget {
},
),
animationDuration: Duration.zero,
shape: MaterialStateProperty.all<OutlinedBorder>(
RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
shape: MaterialStateProperty.all(
RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)),
),
),
onPressed: onPressed,
Expand All @@ -67,7 +66,7 @@ class CustomButton extends StatelessWidget {
),
),
),
)
),
],
),
);
Expand Down
115 changes: 59 additions & 56 deletions lib/widgets/job_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,31 +79,18 @@ class JobPanel extends ConsumerWidget {
}
}

class _JobItem extends ConsumerStatefulWidget {
class _JobItem extends StatelessWidget {
const _JobItem(this.branch, {required this.jobName, Key? key})
: super(key: key);
final Branch branch;
final String jobName;

@override
ConsumerState<ConsumerStatefulWidget> createState() => _JobItemState();
}

class _JobItemState extends ConsumerState<_JobItem> {
late bool _loadBuilding;

@override
initState() {
_loadBuilding = false;
super.initState();
}

@override
Widget build(BuildContext context) {
return Row(
children: [
Text(
widget.branch.name,
branch.name,
style: context.headline6,
),
const SizedBox(
Expand All @@ -112,7 +99,7 @@ class _JobItemState extends ConsumerState<_JobItem> {
InkWell(
onTap: () async {
context.go('/home/build_detail');
final url = await JenkinsApi.recentBuildUrl(widget.branch.url);
final url = await JenkinsApi.recentBuildUrl(branch.url);
if (url != null) {
context.go('/home/build_detail', extra: url);
} else {
Expand All @@ -121,41 +108,64 @@ class _JobItemState extends ConsumerState<_JobItem> {
icon: LineIcons.infoCircle);
}
},
child: (widget.branch.isRunning)
child: (branch.isRunning)
? const RunningWidget()
: CircleAvatar(
radius: 6,
backgroundColor: widget.branch.statusColor,
backgroundColor: branch.statusColor,
),
),
const Spacer(),
Material(
color: Colors.transparent,
child: Builder(
builder: (context) {
if (_loadBuilding) {
return const Padding(
padding: EdgeInsets.all(10),
child: SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
strokeWidth: 1,
),
),
);
}
return IconButton(
splashRadius: 20,
icon: Icon(
LineIcons.running,
color: context.accentColor,
),
onPressed: () => _onBuild(context),
);
},
child: _RunningButton(branch: branch, jobName: jobName),
),
],
);
}
}

class _RunningButton extends ConsumerStatefulWidget {
final Branch branch;
final String jobName;
const _RunningButton({required this.branch, required this.jobName, Key? key})
: super(key: key);

@override
ConsumerState<ConsumerStatefulWidget> createState() => __RunningButtonState();
}

class __RunningButtonState extends ConsumerState<_RunningButton> {
late bool _loadBuilding;
@override
void initState() {
_loadBuilding = false;
super.initState();
}

@override
Widget build(BuildContext context) {
return IndexedStack(
index: _loadBuilding ? 0 : 1,
children: [
const Padding(
padding: EdgeInsets.all(10),
child: SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
strokeWidth: 1,
),
),
),
IconButton(
splashRadius: 20,
icon: Icon(
LineIcons.running,
color: context.accentColor,
),
onPressed: () => _onBuild(context),
)
],
);
}
Expand All @@ -172,6 +182,7 @@ class _JobItemState extends ConsumerState<_JobItem> {
} else {
showPopover(
context: context,
direction: PopoverDirection.top,
barrierColor: Colors.transparent,
transitionDuration: const Duration(milliseconds: 150),
bodyBuilder: (context) {
Expand All @@ -181,16 +192,8 @@ class _JobItemState extends ConsumerState<_JobItem> {
_RunBuildWidget(widget.branch, buildParams, widget.jobName),
);
},
shadow: const [
BoxShadow(
color: Colors.black12,
spreadRadius: 2,
blurRadius: 5,
offset: Offset(-1, 1))
],
onPop: () {},
direction: PopoverDirection.top,
arrowHeight: 15,
arrowHeight: 0,
arrowWidth: 30,
);
}
Expand Down Expand Up @@ -220,20 +223,20 @@ class __RunBuildState extends ConsumerState<_RunBuildWidget> {
final _buildParam = <String, dynamic>{};
@override
void initState() {
for (var param in widget.buildParams) {
super.initState();
for (final param in widget.buildParams) {
_buildParam[param.name] = param.defautlValue;
}
super.initState();
}

@override
Widget build(BuildContext context) {
return SizedBox(
width: 100,
child: Column(
mainAxisSize: MainAxisSize.min,
child: ListView(
shrinkWrap: true,
children: [
...[for (var p in widget.buildParams) _paramWidget(p)],
for (var p in widget.buildParams) _paramWidget(p),
const SizedBox(
height: 20,
),
Expand Down Expand Up @@ -314,7 +317,7 @@ Future _newBuild(
final url = await JenkinsApi.newBuild(branch, params: buildParam);
final buildNumber = await JenkinsApi.getNextBuildNumber(branch.url);
final task = BuildTask(
name: jobName + '-' + branch.name,
name: '$jobName-${branch.name}',
branchUrl: branch.url,
buildNumber: buildNumber,
buildUrl: url,
Expand Down
Loading

0 comments on commit f840f49

Please sign in to comment.