Comments (9)
Here is example of code from one my application:
class LogsPage extends StatefulWidget {
const LogsPage({Key? key, this.from, this.to}) : super(key: key);
final DateTime? from;
final DateTime? to;
@override
State<LogsPage> createState() => _LogsPageState();
}
class _LogsPageState extends State<LogsPage> {
final List<Log> allLogs = [];
@override
initState() {
super.initState();
Get.userLogger.info(LogAction.screen("LogsPage"));
load();
}
Future<void> load() async {
final logs = await MyLogger.logs.getByFilter(LogFilter(
startDateTime: widget.from ?? DateTime(2023),
endDateTime: widget.to ?? DateTime.now(),
));
Get.logger.info("Loaded ${logs.length} logs.");
setState(() => allLogs.addAll(logs));
}
@override
Widget build(BuildContext context) {
return DefaultLayout(
title: t.menu.logs,
padding: EdgeInsets.zero,
menuActions: [
PopupMenuItem(
onTap: () async {
final result = await Popup.warning(
title: context.t.dialogs.clearLogs.title,
message: context.t.dialogs.clearLogs.message,
);
if (result == true) {
await MyLogger.logs.deleteAll();
setState(() {
allLogs.clear();
});
Get.userLogger.info(LogAction.button("Cleared logs."));
}
},
child: Text(context.t.logs.clearLogs),
),
],
body: ListView.builder(
padding: const EdgeInsets.only(top: 24, left: 16, right: 16),
reverse: true,
itemBuilder: (context, index) {
return Container(
height: 85.0,
alignment: Alignment.centerLeft,
child: Text(allLogs[index].toString()),
);
},
itemCount: allLogs.length,
),
);
}
}
It only load the logs and show it in the page.
from mylogger.
Thank you so much, that is very kind.
from mylogger.
Not sure why but this code kills my app...
I cannot navigate back and the app is non responsive.
from mylogger.
Can you create simple example project demonstrates your problems?
from mylogger.
//flutter packages
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:my_logger/logger.dart';
import 'package:my_logger/core/constants.dart';
//project packages
import 'package:zandu_mobile_admin/constants/main.dart';
import 'package:zandu_mobile_admin/utils/localize_string.dart';
import 'package:zandu_mobile_admin/widgets/app_bars/appbar_home.dart';
import 'package:zandu_mobile_admin/widgets/drawers/drawer_main.dart';
import 'package:zandu_mobile_admin/state/app/app_store.dart';
import 'package:zandu_mobile_admin/widgets/empty_notifiers/empty_template_standard.dart';
import 'package:zandu_mobile_admin/widgets/loaders/loading_indicator_with_text.dart';
//issues
class ViewLogFileView extends StatefulWidget {
final AppStore appStore;
final DateTime? from;
final DateTime? to;
const ViewLogFileView({
super.key,
required this.appStore,
required this.from,
required this.to,
});
@override
State<ViewLogFileView> createState() => _ViewLogFileViewState();
}
class _ViewLogFileViewState extends State<ViewLogFileView> {
final _fileName = 'view_log_file_view.dart';
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
final _localizeString = LocalizeString();
File? _logsExport;
final List<Log> allLogs = [];
String? allLogsStringified;
@override
void initState() {
super.initState();
_initialize();
}
void _initialize() async {
/* trace */ if (showFunctionPrintStatements) {
print('_initialize function inside $_fileName');
}
final logs = await MyLogger.logs.getByFilter(LogFilter(
startDateTime: widget.from ?? DateTime(2023),
endDateTime: widget.to ?? DateTime.now(),
));
allLogs.addAll(logs);
setState(() {
//update UI
});
}
@override
void dispose() {
super.dispose();
}
Widget _showContent() {
/* trace */ if (showFunctionPrintStatements) {
print('_showContent function inside $_fileName');
}
if (allLogs.length == 0) {
return Expanded(
child: Center(
child: EmptyTemplateStandard(
text: 'navigation_nologs',
icon: 'log_file',
),
),
);
} else {
return Expanded(
child: Padding(
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
child: SingleChildScrollView(
child: ListView.builder(
padding: const EdgeInsets.only(top: 24, left: 16, right: 16),
shrinkWrap: true,
itemBuilder: (context, index) {
return Container(
height: 85.0,
alignment: Alignment.centerLeft,
child: Text(
allLogs[index].toString(),
),
);
},
itemCount: allLogs.length,
),
),
),
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
drawer: Drawer(
child: DrawerMain(
appStore: widget.appStore,
areWeHome: false
),
),
// endDrawer: FilterWidget(),
appBar: HomeAppBar(
appStore: widget.appStore,
title: _localizeString.localize(contexto: context, term: 'app_name'),
scaffoldKey: _scaffoldKey,
// backgroundColor: Theme.of(context).primaryColor,
backgroundColor: const Color(colors_appbar_bg),
searchMode: false,
widgets: const <Widget>[],
isHomeAppBar: false,
backArrowPressed: null,
),
body: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
const SizedBox(
height: 10,
),
Container(
padding: const EdgeInsets.all(16),
child: Row(
children: <Widget>[
Icon(
FontAwesomeIcons.fileLines,
color: Theme
.of(context)
.primaryColor,
),
Container(
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
child: const Divider(height: 1),
),
Text(
_localizeString.localize(contexto: context, term: 'navigation_viewlogfile_sectionheader'),
style: TextStyle(
color: Theme
.of(context)
.primaryColor,
fontWeight: FontWeight.bold,
fontSize: Theme
.of(context)
.textTheme
.headlineMedium!
.fontSize,
),
),
]
),
),
Container(
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
child: const Divider(height: 1),
),
_showContent(),
],
),
);
}
}
from mylogger.
I stringified everything and now i don't have a crash anymore, I couldn't figure out what was causing the issue.
from mylogger.
I cannot find the problem. You should create some executable project instead of copy-pasted code.
from mylogger.
Is there a quick way to do this? I always wondered about that to share code in this manner but never found a quick way to do exactly that.
from mylogger.
The fastest way is:
- Create new simple Flutter project with your code where is the bug
- Create GitHub repository where you upload the Flutter project
- Send me link for the GitHub repository. I can download it, start up, find bug and fix it.
from mylogger.
Related Issues (4)
- Not compatible with intl 0.18.0 HOT 2
- Nothing in the logs HOT 3
- Web support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mylogger.