login_widget.dart 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. import '/components/header_buttons_component_widget.dart';
  2. import '/flutter_flow/flutter_flow_theme.dart';
  3. import '/flutter_flow/flutter_flow_util.dart';
  4. import '/flutter_flow/flutter_flow_widgets.dart';
  5. import '/shared/drawer_component/drawer_component_widget.dart';
  6. import 'dart:ui';
  7. import '/custom_code/actions/index.dart' as actions;
  8. import '/index.dart';
  9. import 'package:aligned_tooltip/aligned_tooltip.dart';
  10. import 'package:easy_debounce/easy_debounce.dart';
  11. import 'package:flutter/material.dart';
  12. import 'package:flutter/scheduler.dart';
  13. import 'package:flutter_spinkit/flutter_spinkit.dart';
  14. import 'package:google_fonts/google_fonts.dart';
  15. import 'package:provider/provider.dart';
  16. import 'login_model.dart';
  17. export 'login_model.dart';
  18. class LoginWidget extends StatefulWidget {
  19. const LoginWidget({super.key});
  20. static String routeName = 'login';
  21. static String routePath = '/login';
  22. @override
  23. State<LoginWidget> createState() => _LoginWidgetState();
  24. }
  25. class _LoginWidgetState extends State<LoginWidget> with RouteAware {
  26. late LoginModel _model;
  27. final scaffoldKey = GlobalKey<ScaffoldState>();
  28. @override
  29. void initState() {
  30. super.initState();
  31. _model = createModel(context, () => LoginModel());
  32. // On page load action.
  33. SchedulerBinding.instance.addPostFrameCallback((_) async {
  34. if (FFAppState().gemeenteSelectId == null ||
  35. FFAppState().gemeenteSelectId == '') {
  36. FFAppState().gemeenteSelectId = '28694';
  37. FFAppState().provincieSelectId = '28666';
  38. safeSetState(() {});
  39. }
  40. });
  41. _model.usernameFieldTextController ??= TextEditingController()
  42. ..addListener(() {
  43. debugLogWidgetClass(_model);
  44. });
  45. _model.usernameFieldFocusNode ??= FocusNode();
  46. _model.passwordFieldTextController ??= TextEditingController()
  47. ..addListener(() {
  48. debugLogWidgetClass(_model);
  49. });
  50. _model.passwordFieldFocusNode ??= FocusNode();
  51. }
  52. @override
  53. void dispose() {
  54. routeObserver.unsubscribe(this);
  55. _model.dispose();
  56. super.dispose();
  57. }
  58. @override
  59. void didUpdateWidget(LoginWidget oldWidget) {
  60. super.didUpdateWidget(oldWidget);
  61. _model.widget = widget;
  62. }
  63. @override
  64. void didChangeDependencies() {
  65. super.didChangeDependencies();
  66. final route = DebugModalRoute.of(context);
  67. if (route != null) {
  68. routeObserver.subscribe(this, route);
  69. }
  70. debugLogGlobalProperty(context);
  71. }
  72. @override
  73. void didPopNext() {
  74. if (mounted && DebugFlutterFlowModelContext.maybeOf(context) == null) {
  75. setState(() => _model.isRouteVisible = true);
  76. debugLogWidgetClass(_model);
  77. }
  78. }
  79. @override
  80. void didPush() {
  81. if (mounted && DebugFlutterFlowModelContext.maybeOf(context) == null) {
  82. setState(() => _model.isRouteVisible = true);
  83. debugLogWidgetClass(_model);
  84. }
  85. }
  86. @override
  87. void didPop() {
  88. _model.isRouteVisible = false;
  89. }
  90. @override
  91. void didPushNext() {
  92. _model.isRouteVisible = false;
  93. }
  94. @override
  95. Widget build(BuildContext context) {
  96. DebugFlutterFlowModelContext.maybeOf(context)
  97. ?.parentModelCallback
  98. ?.call(_model);
  99. context.watch<FFAppState>();
  100. return GestureDetector(
  101. onTap: () {
  102. FocusScope.of(context).unfocus();
  103. FocusManager.instance.primaryFocus?.unfocus();
  104. },
  105. child: Scaffold(
  106. key: scaffoldKey,
  107. backgroundColor: FlutterFlowTheme.of(context).primaryBackground,
  108. drawer: Drawer(
  109. elevation: 16.0,
  110. child: wrapWithModel(
  111. model: _model.drawerComponentModel,
  112. updateCallback: () => safeSetState(() {}),
  113. child: Builder(builder: (_) {
  114. return DebugFlutterFlowModelContext(
  115. rootModel: _model.rootModel,
  116. child: DrawerComponentWidget(),
  117. );
  118. }),
  119. ),
  120. ),
  121. appBar: PreferredSize(
  122. preferredSize: Size.fromHeight(80.0),
  123. child: AppBar(
  124. backgroundColor: FlutterFlowTheme.of(context).info,
  125. iconTheme:
  126. IconThemeData(color: FlutterFlowTheme.of(context).secondary),
  127. automaticallyImplyLeading: false,
  128. actions: [],
  129. flexibleSpace: FlexibleSpaceBar(
  130. background: wrapWithModel(
  131. model: _model.headerButtonsComponentModel,
  132. updateCallback: () => safeSetState(() {}),
  133. child: Builder(builder: (_) {
  134. return DebugFlutterFlowModelContext(
  135. rootModel: _model.rootModel,
  136. child: HeaderButtonsComponentWidget(
  137. showBackButton: false,
  138. ),
  139. );
  140. }),
  141. ),
  142. centerTitle: true,
  143. expandedTitleScale: 1.0,
  144. ),
  145. bottom: PreferredSize(
  146. preferredSize: Size.fromHeight(70.0),
  147. child: Container(),
  148. ),
  149. toolbarHeight: MediaQuery.sizeOf(context).height * 0.25,
  150. elevation: 2.0,
  151. ),
  152. ),
  153. body: SafeArea(
  154. top: true,
  155. child: Column(
  156. mainAxisSize: MainAxisSize.max,
  157. children: [
  158. Column(
  159. mainAxisSize: MainAxisSize.max,
  160. children: [
  161. Stack(
  162. children: [
  163. Column(
  164. mainAxisSize: MainAxisSize.max,
  165. children: [
  166. AlignedTooltip(
  167. content: Padding(
  168. padding: EdgeInsets.all(4.0),
  169. child: Text(
  170. FFLocalizations.of(context).getText(
  171. 'pj545url' /* Veld wissen */,
  172. ),
  173. style: FlutterFlowTheme.of(context)
  174. .bodyLarge
  175. .override(
  176. font: GoogleFonts.roboto(
  177. fontWeight: FlutterFlowTheme.of(context)
  178. .bodyLarge
  179. .fontWeight,
  180. fontStyle: FlutterFlowTheme.of(context)
  181. .bodyLarge
  182. .fontStyle,
  183. ),
  184. letterSpacing: 0.0,
  185. fontWeight: FlutterFlowTheme.of(context)
  186. .bodyLarge
  187. .fontWeight,
  188. fontStyle: FlutterFlowTheme.of(context)
  189. .bodyLarge
  190. .fontStyle,
  191. ),
  192. ),
  193. ),
  194. offset: 4.0,
  195. preferredDirection: AxisDirection.down,
  196. borderRadius: BorderRadius.circular(8.0),
  197. backgroundColor: FlutterFlowTheme.of(context)
  198. .secondaryBackground,
  199. elevation: 4.0,
  200. tailBaseWidth: 24.0,
  201. tailLength: 12.0,
  202. waitDuration: Duration(milliseconds: 100),
  203. showDuration: Duration(milliseconds: 1500),
  204. triggerMode: TooltipTriggerMode.tap,
  205. child: Container(
  206. width: 200.0,
  207. child: TextFormField(
  208. controller: _model.usernameFieldTextController,
  209. focusNode: _model.usernameFieldFocusNode,
  210. onChanged: (_) => EasyDebounce.debounce(
  211. '_model.usernameFieldTextController',
  212. Duration(milliseconds: 2000),
  213. () => safeSetState(() {}),
  214. ),
  215. autofocus: false,
  216. textInputAction: TextInputAction.next,
  217. obscureText: false,
  218. decoration: InputDecoration(
  219. isDense: true,
  220. labelStyle: FlutterFlowTheme.of(context)
  221. .labelMedium
  222. .override(
  223. font: GoogleFonts.roboto(
  224. fontWeight:
  225. FlutterFlowTheme.of(context)
  226. .labelMedium
  227. .fontWeight,
  228. fontStyle:
  229. FlutterFlowTheme.of(context)
  230. .labelMedium
  231. .fontStyle,
  232. ),
  233. letterSpacing: 0.0,
  234. fontWeight: FlutterFlowTheme.of(context)
  235. .labelMedium
  236. .fontWeight,
  237. fontStyle: FlutterFlowTheme.of(context)
  238. .labelMedium
  239. .fontStyle,
  240. ),
  241. hintText: FFLocalizations.of(context).getText(
  242. 'd507d3b9' /* E-mailadres */,
  243. ),
  244. hintStyle: FlutterFlowTheme.of(context)
  245. .labelMedium
  246. .override(
  247. font: GoogleFonts.roboto(
  248. fontWeight:
  249. FlutterFlowTheme.of(context)
  250. .labelMedium
  251. .fontWeight,
  252. fontStyle:
  253. FlutterFlowTheme.of(context)
  254. .labelMedium
  255. .fontStyle,
  256. ),
  257. letterSpacing: 0.0,
  258. fontWeight: FlutterFlowTheme.of(context)
  259. .labelMedium
  260. .fontWeight,
  261. fontStyle: FlutterFlowTheme.of(context)
  262. .labelMedium
  263. .fontStyle,
  264. ),
  265. enabledBorder: OutlineInputBorder(
  266. borderSide: BorderSide(
  267. color: Color(0x00000000),
  268. width: 1.0,
  269. ),
  270. borderRadius: BorderRadius.circular(8.0),
  271. ),
  272. focusedBorder: OutlineInputBorder(
  273. borderSide: BorderSide(
  274. color: Color(0x00000000),
  275. width: 1.0,
  276. ),
  277. borderRadius: BorderRadius.circular(8.0),
  278. ),
  279. errorBorder: OutlineInputBorder(
  280. borderSide: BorderSide(
  281. color: FlutterFlowTheme.of(context).error,
  282. width: 1.0,
  283. ),
  284. borderRadius: BorderRadius.circular(8.0),
  285. ),
  286. focusedErrorBorder: OutlineInputBorder(
  287. borderSide: BorderSide(
  288. color: FlutterFlowTheme.of(context).error,
  289. width: 1.0,
  290. ),
  291. borderRadius: BorderRadius.circular(8.0),
  292. ),
  293. filled: true,
  294. fillColor: FlutterFlowTheme.of(context)
  295. .secondaryBackground,
  296. suffixIcon: _model
  297. .usernameFieldTextController!
  298. .text
  299. .isNotEmpty
  300. ? InkWell(
  301. onTap: () async {
  302. _model.usernameFieldTextController
  303. ?.clear();
  304. safeSetState(() {});
  305. },
  306. child: Icon(
  307. Icons.clear,
  308. size: 24.0,
  309. ),
  310. )
  311. : null,
  312. ),
  313. style: FlutterFlowTheme.of(context)
  314. .bodyMedium
  315. .override(
  316. font: GoogleFonts.roboto(
  317. fontWeight: FlutterFlowTheme.of(context)
  318. .bodyMedium
  319. .fontWeight,
  320. fontStyle: FlutterFlowTheme.of(context)
  321. .bodyMedium
  322. .fontStyle,
  323. ),
  324. letterSpacing: 0.0,
  325. fontWeight: FlutterFlowTheme.of(context)
  326. .bodyMedium
  327. .fontWeight,
  328. fontStyle: FlutterFlowTheme.of(context)
  329. .bodyMedium
  330. .fontStyle,
  331. ),
  332. cursorColor:
  333. FlutterFlowTheme.of(context).primaryText,
  334. enableInteractiveSelection: true,
  335. validator: _model
  336. .usernameFieldTextControllerValidator
  337. .asValidator(context),
  338. ),
  339. ),
  340. ),
  341. AlignedTooltip(
  342. content: Padding(
  343. padding: EdgeInsets.all(4.0),
  344. child: Text(
  345. FFLocalizations.of(context).getText(
  346. 'n3cyffso' /* Wachtwoord tonen/verbergen */,
  347. ),
  348. style: FlutterFlowTheme.of(context)
  349. .bodyLarge
  350. .override(
  351. font: GoogleFonts.roboto(
  352. fontWeight: FlutterFlowTheme.of(context)
  353. .bodyLarge
  354. .fontWeight,
  355. fontStyle: FlutterFlowTheme.of(context)
  356. .bodyLarge
  357. .fontStyle,
  358. ),
  359. letterSpacing: 0.0,
  360. fontWeight: FlutterFlowTheme.of(context)
  361. .bodyLarge
  362. .fontWeight,
  363. fontStyle: FlutterFlowTheme.of(context)
  364. .bodyLarge
  365. .fontStyle,
  366. ),
  367. ),
  368. ),
  369. offset: 4.0,
  370. preferredDirection: AxisDirection.down,
  371. borderRadius: BorderRadius.circular(8.0),
  372. backgroundColor: FlutterFlowTheme.of(context)
  373. .secondaryBackground,
  374. elevation: 4.0,
  375. tailBaseWidth: 24.0,
  376. tailLength: 12.0,
  377. waitDuration: Duration(milliseconds: 100),
  378. showDuration: Duration(milliseconds: 1500),
  379. triggerMode: TooltipTriggerMode.tap,
  380. child: Container(
  381. width: 200.0,
  382. child: TextFormField(
  383. controller: _model.passwordFieldTextController,
  384. focusNode: _model.passwordFieldFocusNode,
  385. autofocus: false,
  386. textInputAction: TextInputAction.next,
  387. obscureText: !_model.passwordFieldVisibility,
  388. decoration: InputDecoration(
  389. isDense: true,
  390. labelStyle: FlutterFlowTheme.of(context)
  391. .labelMedium
  392. .override(
  393. font: GoogleFonts.roboto(
  394. fontWeight:
  395. FlutterFlowTheme.of(context)
  396. .labelMedium
  397. .fontWeight,
  398. fontStyle:
  399. FlutterFlowTheme.of(context)
  400. .labelMedium
  401. .fontStyle,
  402. ),
  403. letterSpacing: 0.0,
  404. fontWeight: FlutterFlowTheme.of(context)
  405. .labelMedium
  406. .fontWeight,
  407. fontStyle: FlutterFlowTheme.of(context)
  408. .labelMedium
  409. .fontStyle,
  410. ),
  411. hintText: FFLocalizations.of(context).getText(
  412. 't8h5f8ir' /* Wachtwoord */,
  413. ),
  414. hintStyle: FlutterFlowTheme.of(context)
  415. .labelMedium
  416. .override(
  417. font: GoogleFonts.roboto(
  418. fontWeight:
  419. FlutterFlowTheme.of(context)
  420. .labelMedium
  421. .fontWeight,
  422. fontStyle:
  423. FlutterFlowTheme.of(context)
  424. .labelMedium
  425. .fontStyle,
  426. ),
  427. letterSpacing: 0.0,
  428. fontWeight: FlutterFlowTheme.of(context)
  429. .labelMedium
  430. .fontWeight,
  431. fontStyle: FlutterFlowTheme.of(context)
  432. .labelMedium
  433. .fontStyle,
  434. ),
  435. enabledBorder: OutlineInputBorder(
  436. borderSide: BorderSide(
  437. color: Color(0x00000000),
  438. width: 1.0,
  439. ),
  440. borderRadius: BorderRadius.circular(8.0),
  441. ),
  442. focusedBorder: OutlineInputBorder(
  443. borderSide: BorderSide(
  444. color: Color(0x00000000),
  445. width: 1.0,
  446. ),
  447. borderRadius: BorderRadius.circular(8.0),
  448. ),
  449. errorBorder: OutlineInputBorder(
  450. borderSide: BorderSide(
  451. color: FlutterFlowTheme.of(context).error,
  452. width: 1.0,
  453. ),
  454. borderRadius: BorderRadius.circular(8.0),
  455. ),
  456. focusedErrorBorder: OutlineInputBorder(
  457. borderSide: BorderSide(
  458. color: FlutterFlowTheme.of(context).error,
  459. width: 1.0,
  460. ),
  461. borderRadius: BorderRadius.circular(8.0),
  462. ),
  463. filled: true,
  464. fillColor: FlutterFlowTheme.of(context)
  465. .secondaryBackground,
  466. suffixIcon: InkWell(
  467. onTap: () async {
  468. safeSetState(() =>
  469. _model.passwordFieldVisibility =
  470. !_model.passwordFieldVisibility);
  471. },
  472. focusNode: FocusNode(skipTraversal: true),
  473. child: Icon(
  474. _model.passwordFieldVisibility
  475. ? Icons.visibility_outlined
  476. : Icons.visibility_off_outlined,
  477. size: 24.0,
  478. ),
  479. ),
  480. ),
  481. style: FlutterFlowTheme.of(context)
  482. .bodyMedium
  483. .override(
  484. font: GoogleFonts.roboto(
  485. fontWeight: FlutterFlowTheme.of(context)
  486. .bodyMedium
  487. .fontWeight,
  488. fontStyle: FlutterFlowTheme.of(context)
  489. .bodyMedium
  490. .fontStyle,
  491. ),
  492. letterSpacing: 0.0,
  493. fontWeight: FlutterFlowTheme.of(context)
  494. .bodyMedium
  495. .fontWeight,
  496. fontStyle: FlutterFlowTheme.of(context)
  497. .bodyMedium
  498. .fontStyle,
  499. ),
  500. cursorColor:
  501. FlutterFlowTheme.of(context).primaryText,
  502. enableInteractiveSelection: true,
  503. validator: _model
  504. .passwordFieldTextControllerValidator
  505. .asValidator(context),
  506. ),
  507. ),
  508. ),
  509. FFButtonWidget(
  510. onPressed: () async {
  511. _model.resultDrupalLogin =
  512. await actions.drupalLogin(
  513. _model.usernameFieldTextController.text,
  514. _model.passwordFieldTextController.text,
  515. 'https://uitgaanskrant.com/en/flutterdrup/user/login.json',
  516. );
  517. if (_model.resultDrupalLogin != null) {
  518. ScaffoldMessenger.of(context).showSnackBar(
  519. SnackBar(
  520. content: Text(
  521. 'Succesvol ingelogd!',
  522. style: TextStyle(
  523. color: FlutterFlowTheme.of(context)
  524. .primaryText,
  525. ),
  526. ),
  527. duration: Duration(milliseconds: 4000),
  528. backgroundColor:
  529. FlutterFlowTheme.of(context).secondary,
  530. ),
  531. );
  532. } else {
  533. ScaffoldMessenger.of(context).showSnackBar(
  534. SnackBar(
  535. content: Text(
  536. 'Inloggen mislukt. Controleer je gebruikersnaam en wachtwoord.',
  537. style: TextStyle(
  538. color: FlutterFlowTheme.of(context)
  539. .primaryText,
  540. ),
  541. ),
  542. duration: Duration(milliseconds: 4000),
  543. backgroundColor:
  544. FlutterFlowTheme.of(context).secondary,
  545. ),
  546. );
  547. }
  548. safeSetState(() {});
  549. },
  550. text: FFLocalizations.of(context).getText(
  551. 'gkx4luhw' /* Inloggen */,
  552. ),
  553. options: FFButtonOptions(
  554. height: 40.0,
  555. padding: EdgeInsetsDirectional.fromSTEB(
  556. 16.0, 0.0, 16.0, 0.0),
  557. iconPadding: EdgeInsetsDirectional.fromSTEB(
  558. 0.0, 0.0, 0.0, 0.0),
  559. color: FlutterFlowTheme.of(context).secondary,
  560. textStyle: FlutterFlowTheme.of(context)
  561. .titleSmall
  562. .override(
  563. font: GoogleFonts.roboto(
  564. fontWeight: FontWeight.bold,
  565. fontStyle: FlutterFlowTheme.of(context)
  566. .titleSmall
  567. .fontStyle,
  568. ),
  569. color: Colors.white,
  570. fontSize: 24.0,
  571. letterSpacing: 0.0,
  572. fontWeight: FontWeight.bold,
  573. fontStyle: FlutterFlowTheme.of(context)
  574. .titleSmall
  575. .fontStyle,
  576. ),
  577. elevation: 0.0,
  578. borderRadius: BorderRadius.circular(8.0),
  579. ),
  580. ),
  581. InkWell(
  582. splashColor: Colors.transparent,
  583. focusColor: Colors.transparent,
  584. hoverColor: Colors.transparent,
  585. highlightColor: Colors.transparent,
  586. onTap: () async {
  587. context.pushNamed(
  588. WachtwoordVergetenWidget.routeName);
  589. },
  590. child: Text(
  591. FFLocalizations.of(context).getText(
  592. 'utppw2si' /* Wachtwoord vergeten? */,
  593. ),
  594. style: FlutterFlowTheme.of(context)
  595. .bodyMedium
  596. .override(
  597. font: GoogleFonts.roboto(
  598. fontWeight: FlutterFlowTheme.of(context)
  599. .bodyMedium
  600. .fontWeight,
  601. fontStyle: FlutterFlowTheme.of(context)
  602. .bodyMedium
  603. .fontStyle,
  604. ),
  605. letterSpacing: 0.0,
  606. fontWeight: FlutterFlowTheme.of(context)
  607. .bodyMedium
  608. .fontWeight,
  609. fontStyle: FlutterFlowTheme.of(context)
  610. .bodyMedium
  611. .fontStyle,
  612. ),
  613. ),
  614. ),
  615. ],
  616. ),
  617. ],
  618. ),
  619. ],
  620. ),
  621. ],
  622. ),
  623. ),
  624. ),
  625. );
  626. }
  627. }