Skip to content

Commit

Permalink
Merge pull request #4 from srnunio/emartins-example
Browse files Browse the repository at this point in the history
emartins-fixes-and-improvements
  • Loading branch information
srnunio authored Aug 31, 2023
2 parents 63ac915 + 7688ba4 commit e744cec
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 82 deletions.
30 changes: 12 additions & 18 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:activsy/activsy.dart';
import 'package:example/src/authentication.dart';
import 'package:example/src/transactions.dart';
import 'package:example/src/secure_page.dart';
import 'package:example/src/transactions_page.dart';
import 'package:flutter/material.dart';

void main() {
Expand All @@ -22,8 +22,7 @@ class _AppState extends State<App> {
}

void onTimeOut() async {
debugPrint('onTimeOut :)');
await _globalKey.currentState!.pushNamed(AuthenticationPage.route);
await _globalKey.currentState!.pushNamed(SecurePage.route);
Activsy.start();
}

Expand All @@ -47,21 +46,16 @@ class _AppState extends State<App> {
primarySwatch: Colors.blue,
),
initialRoute: '/',
onGenerateRoute: AppRouter.route,
onGenerateRoute: (settings) {
switch (settings.name) {
case SecurePage.route:
return MaterialPageRoute(builder: (_) => SecurePage());
default:
return MaterialPageRoute(builder: (_) => TransactionsPage());
}
},
);
},
);
}
}

abstract class AppRouter {
static Route<dynamic> route(RouteSettings settings) {
debugPrint("route:: ${settings.name}");
switch (settings.name) {
case AuthenticationPage.route:
return MaterialPageRoute(builder: (_) => AuthenticationPage());
default:
return MaterialPageRoute(builder: (_) => TransactionsPage());
}
}
}
}
43 changes: 0 additions & 43 deletions example/lib/src/authentication.dart

This file was deleted.

106 changes: 106 additions & 0 deletions example/lib/src/secure_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';

class SecurePage extends StatefulWidget {
static const route = '/SecurePage';

@override
State<SecurePage> createState() => _SecurePageState();
}

class _SecurePageState extends State<SecurePage> {
List<String> get NUMBERS =>
const ['1', '2', '3', '4', '5', '6', '7', '8', '9', '', '0', ''];

String _pin = "- - - - - -";

/// set up pin
void setPin(String value) {
if (value.isEmpty) return;

var values = _pin.split('');

var index = values.indexOf('-');

if (index < 0) return;

values[index] = value;

setState(() => _pin = values.join());
unlock();
}

void unlock() {
if (_pin.contains('-')) return;
Navigator.pop(context);
}

@override
Widget build(BuildContext context) {
var items = NUMBERS;
return Scaffold(
body: WillPopScope(
child: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
const SizedBox(height: 16.0),
const Text('Set up PIN',
style:
TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold)),
Expanded(
child: Center(
child: Text(
_pin,
style: const TextStyle(fontSize: 50.0),
),
)),
const Text('You can use this PIN to unlock the app.'),
Expanded(
flex: 3,
child: Container(
padding: const EdgeInsets.all(16.0),
child: StaggeredGrid.count(
axisDirection: AxisDirection.down,
crossAxisCount: 3,
crossAxisSpacing: 10.0,
mainAxisSpacing: 10.0,
children: List.generate(
items.length,
(index) {
var item = items[index];
return StaggeredGridTile.count(
crossAxisCellCount: 1,
mainAxisCellCount: 1,
child: Container(
decoration: BoxDecoration(
color: item.isEmpty
? Colors.transparent
: Colors.grey[200],
borderRadius: BorderRadius.circular(90)),
child: MaterialButton(
onPressed: () => setPin(item),
child: Text(
item,
style: const TextStyle(fontSize: 24.0),
),
highlightColor: Colors.transparent,
splashColor: Colors.transparent,
),
),
);
},
),
),
alignment: Alignment.bottomCenter,
),
),
],
),
),
onWillPop: () => Future.value(false),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ class _TransactionsPageState extends State<TransactionsPage> {
Text.rich(TextSpan(children: [
TextSpan(
text: "\$${item['amount']}",
style: const TextStyle(fontSize: 14.0, color: Colors.grey)),
style: const TextStyle(
fontSize: 14.0, color: Colors.grey)),
const TextSpan(
text: " • ",
style: TextStyle(fontSize: 14.0, color: Colors.grey)),
TextSpan(
text: "${item['status']}",
style: const TextStyle(fontSize: 14.0, color: Colors.grey))
style: const TextStyle(
fontSize: 14.0, color: Colors.grey))
]))
],
)
Expand All @@ -79,7 +81,6 @@ class _TransactionsPageState extends State<TransactionsPage> {

@override
void initState() {
// TODO: implement initState
super.initState();

Future.delayed(const Duration(milliseconds: 300), () {
Expand All @@ -90,9 +91,7 @@ class _TransactionsPageState extends State<TransactionsPage> {

_controller.addListener(() {
if (_controller.position.pixels >
_controller.position.maxScrollExtent - 50) {
fetchData();
}
_controller.position.maxScrollExtent - 50) fetchData();
});

fetchData();
Expand All @@ -105,10 +104,7 @@ class _TransactionsPageState extends State<TransactionsPage> {
title: const Text('Transactions'),
),
body: Column(
children: [
const SizedBox(height: 10),
Expanded(child: _bodyList())
],
children: [const SizedBox(height: 10), Expanded(child: _bodyList())],
),
);
}
Expand Down
20 changes: 10 additions & 10 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.2"
version: "1.0.3"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -77,6 +77,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.4"
flutter_staggered_grid_view:
dependency: "direct main"
description:
name: flutter_staggered_grid_view
sha256: "1312314293acceb65b92754298754801b0e1f26a1845833b740b30415bbbcf07"
url: "https://pub.dev"
source: hosted
version: "0.6.2"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -130,14 +138,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.8.3"
pin_code_view:
dependency: "direct main"
description:
name: pin_code_view
sha256: "5f23f03b94d282b3b726f7570ddc4fb3c2ba685db2fc8f2a0ca91b70e814ad72"
url: "https://pub.dev"
source: hosted
version: "0.3.0+2"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -201,4 +201,4 @@ packages:
version: "2.1.4"
sdks:
dart: ">=3.0.0-0 <4.0.0"
flutter: ">=1.17.0"
flutter: ">=2.0.0"
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
pin_code_view: ^0.3.0+2
flutter_staggered_grid_view: ^0.6.0
activsy:
path: ../

Expand Down

0 comments on commit e744cec

Please sign in to comment.