hydro 0.0.1-beta1 copy "hydro: ^0.0.1-beta1" to clipboard
hydro: ^0.0.1-beta1 copied to clipboard

outdated

A simple, fast state management & service container solution for Flutter, without acrobatics.

example/lib/main.dart

import 'package:example/some_class.dart';
import 'package:example/some_page.dart';
import 'package:flutter/material.dart';
import 'package:hydro/hydro.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Hydro Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  late SomeClass someClass;

  @override
  void initState() {
    Hydro.set(SomeClass());
    someClass = Hydro.mustGet<SomeClass>(this);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              "${someClass.counter}",
              style: Theme.of(context).textTheme.headline4,
            ),
            Text(
              "Name: ${someClass.name}",
              style: Theme.of(context).textTheme.headline5,
            ),
            ElevatedButton(
                onPressed: () {
                  Navigator.push(
                      context, MaterialPageRoute(builder: (ctx) => const SomePage()));
                },
                child: const Text("Some Page"))
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          someClass.incrementCounter();
        },
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}
4
likes
0
pub points
17%
popularity

Publisher

verified publisherfiras.dev.sy

A simple, fast state management & service container solution for Flutter, without acrobatics.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

collection, flutter

More

Packages that depend on hydro