我想使用local_auth合并指纹认证,但不能。您能否在我的代码中提供帮助,以便指纹验证后进入MyHomePage。 提前致谢。我已经在local_auth上尝试了他们的示例,但没有获得使用方法。
我不介意是否需要2个屏幕。
import 'dart:io';
import 'package:expense_planner/screens/edit_transaction.dart';
import 'package:expense_planner/screens/new_transaction.dart';
import 'package:expense_planner/services/service_locator.dart';
import 'package:expense_planner/widgets/chart.dart';
import 'package:expense_planner/widgets/transaction_list.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:flutter/services.dart';
import 'providers/transactions.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
setupLocator();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider.value(
value: Transactions(),
child: MaterialApp(
title: 'Expense Tracker',
theme: ThemeData(
primarySwatch: Colors.red,
accentColor: Colors.black54,
fontFamily: 'OpenSans',
textTheme: ThemeData.light().textTheme.copyWith(
headline6: TextStyle(
fontFamily: 'OpenSans',
color: Colors.black54,
fontWeight: FontWeight.bold,
),
headline5: TextStyle(
fontFamily: 'OpenSans',
color: Colors.white,
fontWeight: FontWeight.bold,
),
button: TextStyle(color: Colors.white),
),
appBarTheme: AppBarTheme(
textTheme: ThemeData.light().textTheme.copyWith(
headline5: TextStyle(
color: Colors.white,
fontFamily: 'OpenSans',
fontWeight: FontWeight.bold,
),
),
),
),
home: MyHomePage(),
routes: {
EditTransaction.routeName: (ctx) => EditTransaction(),
},
),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
void _startAddNewTransaction(BuildContext ctx) {
showModalBottomSheet(
context: ctx,
builder: (_) {
return GestureDetector(
onTap: () {},
child: NewTransaction(),
);
},
);
}
Widget _buildAppBar() {
return Platform.isIOS
? CupertinoNavigationBar(
middle: Text(
'Expense Tracker',
style: Theme.of(context).textTheme.headline5,
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
GestureDetector(
child: Icon(CupertinoIcons.add),
onTap: () => _startAddNewTransaction(context),
),
],
),
)
: AppBar(
title: Text(
'Expense Tracker',
style: Theme.of(context).textTheme.headline5,
),
actions: <Widget>[
IconButton(
icon: Icon(Icons.add),
onPressed: () => _startAddNewTransaction(context),
),
],
);
}
@override
Widget build(BuildContext context) {
final mediaQuery = MediaQuery.of(context);
// final isLandscape = mediaQuery.orientation == Orientation.landscape;
final PreferredSizeWidget appBar = _buildAppBar();
final pageBody = SafeArea(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
height: (mediaQuery.size.height -
appBar.preferredSize.height -
mediaQuery.padding.top) *
0.3,
child: Chart(),
),
Container(
height: (mediaQuery.size.height -
appBar.preferredSize.height -
mediaQuery.padding.top) *
0.7,
child: TransactionList(),
)
],
),
),
);
return Platform.isIOS
? CupertinoPageScaffold(
navigationBar: appBar,
child: pageBody,
)
: Scaffold(
appBar: appBar,
body: pageBody,
floatingActionButtonLocation:
FloatingActionButtonLocation.centerFloat,
floatingActionButton: Platform.isIOS // checking is platform is IOS
? Container() // we r avoiding floatingActionButton
: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () => _startAddNewTransaction(context),
),
);
}
}