add buildlogprovider to handle scrolling from outside widget
This commit is contained in:
parent
7ea241112c
commit
598159a2bc
@ -3,7 +3,7 @@ import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../providers/BaseProvider.dart';
|
||||
import '../../providers/api/BaseProvider.dart';
|
||||
|
||||
class APIBuilder<T extends BaseProvider, K, DTO> extends StatefulWidget {
|
||||
const APIBuilder(
|
||||
|
@ -2,9 +2,11 @@ import 'dart:async';
|
||||
|
||||
import 'package:aurcache/api/builds.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../api/API.dart';
|
||||
import '../models/build.dart';
|
||||
import '../providers/build_log_provider.dart';
|
||||
|
||||
class BuildOutput extends StatefulWidget {
|
||||
const BuildOutput({super.key, required this.build});
|
||||
@ -20,14 +22,15 @@ class _BuildOutputState extends State<BuildOutput> {
|
||||
|
||||
String output = "";
|
||||
Timer? outputTimer;
|
||||
final scrollController = ScrollController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final sc =
|
||||
Provider.of<BuildLogProvider>(context, listen: false).scrollController;
|
||||
return Expanded(
|
||||
flex: 1,
|
||||
child: SingleChildScrollView(
|
||||
controller: scrollController,
|
||||
controller: sc,
|
||||
scrollDirection: Axis.vertical, //.horizontal
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 30, right: 15),
|
||||
@ -57,38 +60,28 @@ class _BuildOutputState extends State<BuildOutput> {
|
||||
setState(() {
|
||||
output = value;
|
||||
});
|
||||
_scrollToBottom();
|
||||
Provider.of<BuildLogProvider>(context, listen: false).go_to_bottom();
|
||||
});
|
||||
|
||||
// poll new output only if not finished
|
||||
if (widget.build.status == 0) {
|
||||
outputTimer = Timer.periodic(const Duration(seconds: 3), (Timer t) async {
|
||||
print("refreshing output");
|
||||
final value = await API.getOutput(
|
||||
buildID: widget.build.id, line: output.split("\n").length);
|
||||
setState(() {
|
||||
output += value;
|
||||
});
|
||||
final follow =
|
||||
Provider.of<BuildLogProvider>(context, listen: false).followLog;
|
||||
if (follow) {
|
||||
print("refreshing output");
|
||||
final value = await API.getOutput(
|
||||
buildID: widget.build.id, line: output.split("\n").length);
|
||||
setState(() {
|
||||
output += value;
|
||||
});
|
||||
|
||||
_scrollToBottom();
|
||||
Provider.of<BuildLogProvider>(context, listen: false).go_to_bottom();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _scrollToBottom() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// scroll to bottom
|
||||
final scrollPosition = scrollController.position;
|
||||
if (scrollPosition.viewportDimension < scrollPosition.maxScrollExtent) {
|
||||
scrollController.animateTo(
|
||||
scrollPosition.maxScrollExtent,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.easeOut,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:aurcache/components/builds_table.dart';
|
||||
import 'package:aurcache/models/build.dart';
|
||||
import 'package:aurcache/components/api/APIBuilder.dart';
|
||||
import 'package:aurcache/providers/builds_provider.dart';
|
||||
import 'package:aurcache/providers/api/builds_provider.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../constants/color_constants.dart';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'package:aurcache/components/api/APIBuilder.dart';
|
||||
import 'package:aurcache/components/packages_table.dart';
|
||||
import 'package:aurcache/providers/packages_provider.dart';
|
||||
import 'package:aurcache/providers/api/packages_provider.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../constants/color_constants.dart';
|
||||
|
@ -6,9 +6,9 @@ import 'package:provider/provider.dart';
|
||||
import '../api/API.dart';
|
||||
import '../constants/color_constants.dart';
|
||||
import '../models/package.dart';
|
||||
import '../providers/builds_provider.dart';
|
||||
import '../providers/packages_provider.dart';
|
||||
import '../providers/stats_provider.dart';
|
||||
import '../providers/api/builds_provider.dart';
|
||||
import '../providers/api/packages_provider.dart';
|
||||
import '../providers/api/stats_provider.dart';
|
||||
import 'confirm_popup.dart';
|
||||
import 'dashboard/your_packages.dart';
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:aurcache/api/aur.dart';
|
||||
import 'package:aurcache/models/aur_package.dart';
|
||||
|
||||
import '../api/API.dart';
|
||||
import '../../api/API.dart';
|
||||
import 'BaseProvider.dart';
|
||||
|
||||
class AurSearchDTO {
|
@ -1,7 +1,7 @@
|
||||
import 'package:aurcache/api/builds.dart';
|
||||
|
||||
import '../api/API.dart';
|
||||
import '../models/build.dart';
|
||||
import '../../api/API.dart';
|
||||
import '../../models/build.dart';
|
||||
import 'BaseProvider.dart';
|
||||
|
||||
class BuildDTO {
|
@ -1,7 +1,7 @@
|
||||
import 'package:aurcache/api/builds.dart';
|
||||
|
||||
import '../api/API.dart';
|
||||
import '../models/build.dart';
|
||||
import '../../api/API.dart';
|
||||
import '../../models/build.dart';
|
||||
import 'BaseProvider.dart';
|
||||
|
||||
class BuildsDTO {
|
@ -1,7 +1,7 @@
|
||||
import 'package:aurcache/api/packages.dart';
|
||||
|
||||
import '../api/API.dart';
|
||||
import '../models/package.dart';
|
||||
import '../../api/API.dart';
|
||||
import '../../models/package.dart';
|
||||
import 'BaseProvider.dart';
|
||||
|
||||
class PackageDTO {
|
@ -1,8 +1,8 @@
|
||||
import 'package:aurcache/api/packages.dart';
|
||||
import 'package:aurcache/providers/BaseProvider.dart';
|
||||
import 'package:aurcache/providers/api/BaseProvider.dart';
|
||||
|
||||
import '../api/API.dart';
|
||||
import '../models/package.dart';
|
||||
import '../../api/API.dart';
|
||||
import '../../models/package.dart';
|
||||
|
||||
class PackagesDTO {
|
||||
final int limit;
|
@ -1,6 +1,6 @@
|
||||
import 'package:aurcache/api/statistics.dart';
|
||||
|
||||
import '../api/API.dart';
|
||||
import '../../api/API.dart';
|
||||
import 'BaseProvider.dart';
|
||||
|
||||
class StatsProvider extends BaseProvider {
|
39
frontend/lib/providers/build_log_provider.dart
Normal file
39
frontend/lib/providers/build_log_provider.dart
Normal file
@ -0,0 +1,39 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
class BuildLogProvider with ChangeNotifier {
|
||||
final scrollController = ScrollController();
|
||||
|
||||
bool followLog = true;
|
||||
|
||||
set follow_log(bool value) {
|
||||
followLog = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void go_to_bottom() {
|
||||
_scrollToBottom();
|
||||
}
|
||||
|
||||
void go_to_top() {
|
||||
final scrollPosition = scrollController.position;
|
||||
scrollController.animateTo(
|
||||
scrollPosition.minScrollExtent,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.easeOut,
|
||||
);
|
||||
}
|
||||
|
||||
void _scrollToBottom() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// scroll to bottom
|
||||
final scrollPosition = scrollController.position;
|
||||
if (scrollPosition.viewportDimension < scrollPosition.maxScrollExtent) {
|
||||
scrollController.animateTo(
|
||||
scrollPosition.maxScrollExtent,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.easeOut,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -2,13 +2,13 @@ import 'dart:async';
|
||||
|
||||
import 'package:aurcache/components/aur_search_table.dart';
|
||||
import 'package:aurcache/models/aur_package.dart';
|
||||
import 'package:aurcache/providers/aur_search_provider.dart';
|
||||
import 'package:aurcache/providers/api/aur_search_provider.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../components/api/APIBuilder.dart';
|
||||
import '../constants/color_constants.dart';
|
||||
import '../providers/packages_provider.dart';
|
||||
import '../providers/api/packages_provider.dart';
|
||||
|
||||
class AurScreen extends StatefulWidget {
|
||||
const AurScreen({super.key, this.initalQuery});
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:aurcache/components/build_output.dart';
|
||||
import 'package:aurcache/models/build.dart';
|
||||
import 'package:aurcache/components/api/APIBuilder.dart';
|
||||
import 'package:aurcache/providers/build_provider.dart';
|
||||
import 'package:aurcache/providers/build_log_provider.dart';
|
||||
import 'package:aurcache/utils/time_formatter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
@ -11,6 +11,7 @@ import '../components/confirm_popup.dart';
|
||||
import '../components/dashboard/chart_card.dart';
|
||||
import '../components/dashboard/your_packages.dart';
|
||||
import '../constants/color_constants.dart';
|
||||
import '../providers/api/build_provider.dart';
|
||||
|
||||
class BuildScreen extends StatefulWidget {
|
||||
const BuildScreen({super.key, required this.buildID});
|
||||
@ -22,44 +23,50 @@ class BuildScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _BuildScreenState extends State<BuildScreen> {
|
||||
bool scrollFollowActive = true;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider<BuildProvider>(create: (_) => BuildProvider()),
|
||||
ChangeNotifierProvider<BuildLogProvider>(
|
||||
create: (_) => BuildLogProvider()),
|
||||
],
|
||||
child: APIBuilder<BuildProvider, Build, BuildDTO>(
|
||||
key: const Key("Build on seperate page"),
|
||||
dto: BuildDTO(buildID: widget.buildID),
|
||||
interval: const Duration(seconds: 10),
|
||||
onLoad: () => const Text("loading"),
|
||||
onData: (buildData) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
_buildTopBar(buildData),
|
||||
const SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
_buildPage(buildData)
|
||||
],
|
||||
builder: (context, child) {
|
||||
return APIBuilder<BuildProvider, Build, BuildDTO>(
|
||||
key: const Key("Build on seperate page"),
|
||||
dto: BuildDTO(buildID: widget.buildID),
|
||||
interval: const Duration(seconds: 10),
|
||||
onLoad: () => const Text("loading"),
|
||||
onData: (buildData) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
_buildTopBar(buildData, context),
|
||||
const SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
_buildPage(buildData)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildSideBar(),
|
||||
],
|
||||
);
|
||||
}),
|
||||
_buildSideBar(),
|
||||
],
|
||||
);
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTopBar(Build buildData) {
|
||||
Widget _buildTopBar(Build buildData, BuildContext context) {
|
||||
final start_time =
|
||||
DateTime.fromMillisecondsSinceEpoch((buildData.start_time ?? 0) * 1000);
|
||||
|
||||
@ -113,18 +120,32 @@ class _BuildScreenState extends State<BuildScreen> {
|
||||
Row(
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
scrollFollowActive = !scrollFollowActive;
|
||||
Provider.of<BuildLogProvider>(context, listen: false)
|
||||
.followLog = scrollFollowActive;
|
||||
});
|
||||
},
|
||||
isSelected: scrollFollowActive,
|
||||
icon: const Icon(Icons.read_more),
|
||||
selectedIcon: const Icon(Icons.read_more),
|
||||
tooltip: "Follow log",
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
onPressed: () {
|
||||
Provider.of<BuildLogProvider>(context, listen: false)
|
||||
.go_to_top();
|
||||
},
|
||||
icon: const Icon(Icons.vertical_align_top_rounded),
|
||||
tooltip: "Go to Top",
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
icon: Icon(Icons.vertical_align_bottom_rounded),
|
||||
onPressed: () {
|
||||
Provider.of<BuildLogProvider>(context, listen: false)
|
||||
.go_to_bottom();
|
||||
},
|
||||
icon: const Icon(Icons.vertical_align_bottom_rounded),
|
||||
tooltip: "Go to Bottom",
|
||||
),
|
||||
const SizedBox(
|
||||
@ -164,12 +185,11 @@ class _BuildScreenState extends State<BuildScreen> {
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
final confirmResult = await showConfirmationDialog(
|
||||
context,
|
||||
"Delete Build",
|
||||
"Are you sure to delete this Package?",
|
||||
() async {},
|
||||
() {},
|
||||
);
|
||||
context,
|
||||
"Delete Build",
|
||||
"Are you sure to delete this Package?", () async {
|
||||
// todo delete build
|
||||
}, null);
|
||||
},
|
||||
child: const Text(
|
||||
"Delete",
|
||||
@ -181,13 +201,7 @@ class _BuildScreenState extends State<BuildScreen> {
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
final confirmResult = await showConfirmationDialog(
|
||||
context,
|
||||
"Delete Build",
|
||||
"Are you sure to delete this Package?",
|
||||
() async {},
|
||||
() {},
|
||||
);
|
||||
// todo api call and page redirect
|
||||
},
|
||||
child: const Text(
|
||||
"Retry",
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'package:aurcache/components/builds_table.dart';
|
||||
import 'package:aurcache/components/api/APIBuilder.dart';
|
||||
import 'package:aurcache/providers/builds_provider.dart';
|
||||
import 'package:aurcache/providers/api/builds_provider.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../constants/color_constants.dart';
|
||||
|
@ -1,12 +1,12 @@
|
||||
import 'package:aurcache/components/api/APIBuilder.dart';
|
||||
import 'package:aurcache/providers/stats_provider.dart';
|
||||
import 'package:aurcache/providers/api/stats_provider.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../components/dashboard/header.dart';
|
||||
import '../constants/color_constants.dart';
|
||||
import '../providers/builds_provider.dart';
|
||||
import '../providers/packages_provider.dart';
|
||||
import '../providers/api/builds_provider.dart';
|
||||
import '../providers/api/packages_provider.dart';
|
||||
import '../utils/responsive.dart';
|
||||
import '../models/stats.dart';
|
||||
import '../components/dashboard/quick_info_banner.dart';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'package:aurcache/api/packages.dart';
|
||||
import 'package:aurcache/components/api/APIBuilder.dart';
|
||||
import 'package:aurcache/providers/builds_provider.dart';
|
||||
import 'package:aurcache/providers/api/builds_provider.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@ -11,9 +11,9 @@ import '../components/confirm_popup.dart';
|
||||
import '../constants/color_constants.dart';
|
||||
import '../models/build.dart';
|
||||
import '../models/package.dart';
|
||||
import '../providers/package_provider.dart';
|
||||
import '../providers/packages_provider.dart';
|
||||
import '../providers/stats_provider.dart';
|
||||
import '../providers/api/package_provider.dart';
|
||||
import '../providers/api/packages_provider.dart';
|
||||
import '../providers/api/stats_provider.dart';
|
||||
|
||||
class PackageScreen extends StatefulWidget {
|
||||
const PackageScreen({super.key, required this.pkgID});
|
||||
|
@ -1,5 +1,5 @@
|
||||
import 'package:aurcache/components/packages_table.dart';
|
||||
import 'package:aurcache/providers/packages_provider.dart';
|
||||
import 'package:aurcache/providers/api/packages_provider.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user