nylo-core / nylo

Nylo is the fastest way to build your next Flutter mobile app. Streamline your projects with Nylo's opinionated approach to building Flutter apps. Develop your next idea ⚡️
https://nylo.dev
MIT License
597 stars 61 forks source link

validation not working when extends NyPage #86

Closed RoxDevvv closed 11 months ago

RoxDevvv commented 11 months ago

validation not working when extends NyPage

import 'package:flutter/material.dart';
import 'package:nylo_framework/nylo_framework.dart';

class DashboardPage extends NyPage {

  static String path = '/dashboard';

  @override
  init() async {
    // initialize the page
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Dashboard")
      ),
      body: SafeArea(
         child: Container(
             child: Text("Hello World") // Build your UI
         ),
      ),
    );
  }
}
agordn52 commented 11 months ago

Hi @RoxDevvv,

In the example you've provided above, I can't see how you're using validation.

Check out the docs here to learn how to use the validate helper 👍

This is working.

import 'package:flutter/material.dart';
import 'package:nylo_framework/nylo_framework.dart';
import '/app/controllers/dashboard_controller.dart';

class DashboardPage extends NyPage<DashboardController> {

  static String path = '/dashboard';

  @override
  init() async {
    // To update the state, 
    // use: refreshPage(setState: () { }); 
  }

  validateData() {
    // Validate data before proceeding
    validate(rules: {
      "email": "email"
    }, data: {
      "email": "eeee" // bad data
    }, onSuccess: () {

    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Dashboard")
      ),
      body: SafeArea(
         child: Container(
           child: InkWell(
             onTap: () {
               validateData();
             },
             child: Text("Test"),
           ),
         ),
      ),
    );
  }
}