Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ekran skanowania lista wyników #135

Merged
merged 23 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions assets/menuPage/flashlightoff.svg
WezSieTato marked this conversation as resolved.
Show resolved Hide resolved
WezSieTato marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions assets/menuPage/flashlighton.svg
WezSieTato marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions assets/menuPage/showmore.svg
WezSieTato marked this conversation as resolved.
Show resolved Hide resolved
WezSieTato marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 3 additions & 10 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,15 @@ class _PolaAppState extends State<PolaApp> {
body: IndexedStack(
index: _selectedIndex,
children: _tabs,
)
),
)),
),
);
}

final List<Widget> _tabs = [
MainPage(),
WebViewTab(
title: "Wyszukiwarka",
url: "https://www.pola-app.pl/m/search/"
),
WebViewTab(
title: "Wiadomości",
url: "https://www.pola-app.pl/m/blog/"
)
WebViewTab(title: "Wyszukiwarka", url: "https://www.pola-app.pl/m/search/"),
WebViewTab(title: "Wiadomości", url: "https://www.pola-app.pl/m/blog/")
];

AnalyticsMainTab _getTabParameter(int index) {
Expand Down
102 changes: 76 additions & 26 deletions lib/pages/scan/companies_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,57 @@ class CompaniesList extends StatelessWidget {

@override
Widget build(BuildContext context) {
final int listSize = state.list.length;

_scrollToTop();
return Column(mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[
Container(
height: 200,
child: Align(
alignment: Alignment.bottomCenter,
child: ListView.builder(
controller: listScrollController,
reverse: true,
itemCount: state.list.length + (state.isLoading ? 1 : 0),
itemBuilder: (BuildContext context, int index) {
if (index == state.list.length) {
return LoadingListItem();
}
return GestureDetector(
child: ResultListItem(state.list[index]),
onTap: () {
final result = state.list[index];
_analytics.opensCard(result);
Navigator.pushNamed(context, '/detail', arguments: result);
},
);
},

double maxHeight;
if (listSize == 1) {
WezSieTato marked this conversation as resolved.
Show resolved Hide resolved
maxHeight = 47.5;
} else if (listSize == 2) {
maxHeight = 95.0;
} else if (listSize == 3) {
maxHeight = 142.5;
} else {
maxHeight = 190.0;
}

return Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
_ListHeader(listSize: listSize),
Container(
constraints: BoxConstraints(
maxHeight: maxHeight,
),
child: Align(
alignment: Alignment.bottomCenter,
child: ListView.builder(
controller: listScrollController,
reverse: true,
itemCount: listSize + (state.isLoading ? 1 : 0),
itemBuilder: (BuildContext context, int index) {
if (index == listSize) {
return LoadingListItem();
}
return GestureDetector(
child: ResultListItem(state.list[index]),
onTap: () {
final result = state.list[index];
_analytics.opensCard(result);
Navigator.pushNamed(context, '/detail', arguments: result);
},
);
},
),
),
),
),
RemoteButton(RemoteButtonState(
state.list.firstOrNull?.donate, state.list.firstOrNull?.code))
]);
RemoteButton(RemoteButtonState(
state.list.firstOrNull?.donate,
state.list.firstOrNull?.code,
)),
],
);
}

void _scrollToTop() {
Expand All @@ -53,3 +75,31 @@ class CompaniesList extends StatelessWidget {
});
}
}

class _ListHeader extends StatelessWidget {
final int listSize;

const _ListHeader({required this.listSize});

@override
Widget build(BuildContext context) {
if (listSize > 0) {
return Padding(
padding: const EdgeInsets.only(left: 16.0),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
'Ostatnie skany:',
WezSieTato marked this conversation as resolved.
Show resolved Hide resolved
style: TextStyle(
fontSize: 16,
WezSieTato marked this conversation as resolved.
Show resolved Hide resolved
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
);
} else {
return Container();
}
}
}
135 changes: 79 additions & 56 deletions lib/pages/scan/scan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class _MainPageState extends State<MainPage> {
final PolaAnalytics _analytics = PolaAnalytics.instance();

ScrollController listScrollController = ScrollController();
bool _isTorchOn = false;

@override
void initState() {
Expand All @@ -46,10 +47,9 @@ class _MainPageState extends State<MainPage> {
onPressed: () {
_analytics.aboutPolaOpened();
showWebViewDialog(
context: context,
url: "https://www.pola-app.pl/m/about",
title: t.menu.aboutPola
);
context: context,
url: "https://www.pola-app.pl/m/about",
title: t.menu.aboutPola);
},
icon: Assets.icLauncher.image(),
),
Expand Down Expand Up @@ -87,55 +87,77 @@ class _MainPageState extends State<MainPage> {
child: Column(
children: <Widget>[
Center(
child: Padding(
padding: const EdgeInsets.only(top: 20.0),
child: Text(
"Umieść kod kreskowy produktu w prostokącie powyżej aby dowiedzieć się więcej o firmie, która go wyprodukowała.",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
)))),
child: Padding(
padding: const EdgeInsets.only(top: 20.0),
child: Text(
"Umieść kod kreskowy produktu w prostokącie powyżej aby dowiedzieć się więcej o firmie, która go wyprodukowała.",
textAlign: TextAlign.center,
style: TextStyle(color: Colors.white),
),
),
),
],
),
),
SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Spacer(),
BlocBuilder<ScanBloc, ScanState>(
bloc: _scanBloc,
builder: (context, state) {
if (state.isError) {
SchedulerBinding.instance.addPostFrameCallback((_) {
showDialog(
context: context,
barrierDismissible: false,
builder: (_) {
return AlertDialog(
title: Text('Wystąpił błąd'),
content: Text('Niestety nie udało się pobrać danych. Spróbuj ponownie.'),
actions: <Widget>[
TextButton(
child: Text('Zamknij.'),
onPressed: () {
_scanBloc.add(ScanEvent.alertDialogDismissed());
SchedulerBinding.instance.addPostFrameCallback((_) {
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Spacer(),
BlocBuilder<ScanBloc, ScanState>(
bloc: _scanBloc,
builder: (context, state) {
if (state.isError) {
SchedulerBinding.instance.addPostFrameCallback((_) {
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Wystąpił błąd'),
WezSieTato marked this conversation as resolved.
Show resolved Hide resolved
content: Text(
'Niestety nie udało się pobrać danych. Spróbuj ponownie.'),
actions: <Widget>[
TextButton(
child: Text('Zamknij.'),
WezSieTato marked this conversation as resolved.
Show resolved Hide resolved
onPressed: () {
_scanBloc
.add(ScanEvent.alertDialogDismissed());
Navigator.pop(context);
});
},
),
],
);
},
);
});
}
return CompaniesList(state, listScrollController);
},
},
),
],
);
},
);
});
}
return CompaniesList(state, listScrollController);
WezSieTato marked this conversation as resolved.
Show resolved Hide resolved
},
),
],
),
),
Positioned(
bottom: 35,
right: 5,
child: GestureDetector(
onTap: () {
setState(() {
_isTorchOn = !_isTorchOn;
cameraController.toggleTorch();
});
},
child: Container(
decoration: BoxDecoration(
boxShadow: [],
),
child: _isTorchOn
? Assets.menuPage.flashlighton.svg()
: Assets.menuPage.flashlightoff.svg(),
),
],
)),
),
),
],
),
extendBodyBehindAppBar: true,
Expand All @@ -151,15 +173,16 @@ class _MainPageState extends State<MainPage> {
children: [
Positioned.fill(
child: MobileScanner(
controller: cameraController,
onDetect: (capture) {
final List<Barcode> barcodes = capture.barcodes;
for (final barcode in barcodes) {
final String code = barcode.rawValue!;
debugPrint('Barcode found! $code');
_scanBloc.add(ScanEvent.barcodeScanned(code));
}
}),
controller: cameraController,
onDetect: (capture) {
final List<Barcode> barcodes = capture.barcodes;
for (final barcode in barcodes) {
final String code = barcode.rawValue!;
debugPrint('Barcode found! $code');
_scanBloc.add(ScanEvent.barcodeScanned(code));
}
},
),
),
Positioned.fill(
child: Align(
Expand Down
Loading
Loading