I have the following Flutter flow using flow_builder:
import 'package:flow_builder/flow_builder.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:myaccounts/menu_drawer.dart';
// FLOW
class NewAccountFlow extends StatelessWidget {
static Route<Account> route() {
return MaterialPageRoute(builder: (_) => NewAccountFlow());
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: FlowBuilder<Account>(
state: const Account(),
onGeneratePages: (Account, pages) {
return [
MaterialPage(child: NameAccountForm()),
if (Account.name != null) MaterialPage(child: EnterAccountForm()),
];
},
),
);
}
}
// STATE
class Account {
const Account({
this.name,
});
final String? name;
Account copyWith ({String? name}) {
return Account(
name: name ?? this.name,
);
}
}
// FORMS
class NameAccountForm extends HookWidget {
@override
Widget build(BuildContext context) {
final _name = useState<String>('Test');
return Scaffold(
appBar: AppBar(title: const Text('My Accounts')),
drawer: MenuDrawer(),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextField(
autofocus: true,
onChanged: (value) => _name.value = value,
decoration: InputDecoration(
labelText: 'Account Name',
hintText: 'Enter a name for your account',
),
),
const SizedBox(height: 24.0),
RaisedButton(
child: const Text('Continue'),
onPressed: () {
if (_name.value.isNotEmpty) {
context.flow<Account>().update((info) => info.copyWith(name: _name.value));
}
},
)
],
),
);
}
}
class AccountValueField extends StatelessWidget {
const AccountValueField({required this.place, Key? key}) : super(key: key);
final String place;
@override
Widget build(BuildContext context) {
return Padding(
child: TextFormField(
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: place,
contentPadding: const EdgeInsets.symmetric(vertical: 6, horizontal: 10),
isDense: true,
),
//style: TextStyle(
// fontSize: 14,
// height: 1,
//),
),
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 5),
);
}
}
class EnterAccountForm extends HookWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('My Accounts')),
drawer: MenuDrawer(),
body: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
child: const Text('Enter your details:', style: const TextStyle(fontWeight: FontWeight.bold)),
padding: EdgeInsets.symmetric(vertical: 8),
)
]
),
Row(
children: [
Expanded(child: Column(
children: [
AccountValueField(place: '1'),
]
)),
Expanded(child: Column(
children: [
AccountValueField(place: '2'),
]
)),
]
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 2),
child: ElevatedButton(
onPressed: () {
},
child: const Text('Save'),
),
),
]
),
]
)
);
}
}
which keeps throwing this error:
/usr/local/Caskroom/flutter/2.10.5/flutter/.pub-cache/hosted/pub.dartlang.org/flow_builder-0.0.7/lib/flow_builder.dart:367:36: Error: Method 'handlePopRoute' cannot be called on 'WidgetsBinding?'
because it is potentially null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/usr/local/Caskroom/flutter/2.10.5/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
return WidgetsBinding.instance.handlePopRoute();
^^^^^^^^^^^^^^
/usr/local/Caskroom/flutter/2.10.5/flutter/.pub-cache/hosted/pub.dartlang.org/flow_builder-0.0.7/lib/flow_builder.dart:372:38: Error: Method 'handlePushRoute' cannot be called on 'WidgetsBinding?'
because it is potentially null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/usr/local/Caskroom/flutter/2.10.5/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
return WidgetsBinding.instance.handlePushRoute(arguments);
^^^^^^^^^^^^^^^
I'm not sure where this error is coming from. Any help is appreciated.