muse_ai 0.6.0+1 copy "muse_ai: ^0.6.0+1" to clipboard
muse_ai: ^0.6.0+1 copied to clipboard

Integrating with MUSE.ai

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:muse_ai/muse_ai.dart';

import 'collection_view.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  MuseIndex? _index;
  late MuseAI _museAI;
  bool _error = false;
  bool _loading = false;

  @override
  void initState() {
    super.initState();
  }

  _updateApiKey(String key) async {
    _museAI = MuseAI(key);
    setState(() {
      _error = false;
      _loading = true;
    });
    try {
      _index = (await _museAI.collections()).index();
      setState(() {
        _loading = false;
      });
    } catch (e) {
      setState(() {
        _error = true;
        _loading = false;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Builder(
        builder: (context) => Scaffold(
          appBar: AppBar(
            title: const Text('Muse Example App'),
          ),
          body: Container(
            padding: EdgeInsets.all(26),
            child: ListView(
              children: [
                TextField(
                  textCapitalization: TextCapitalization.none,
                  decoration: InputDecoration(
                    labelText: "Paste muse.ai API key",
                  ),
                  onChanged: (value) {
                    _updateApiKey(value);
                  },
                ),
                if (_loading)
                  Container(
                      padding: const EdgeInsets.symmetric(vertical: 16),
                      child: Center(child: CircularProgressIndicator()))
                else if (_error)
                  Container(
                    padding: const EdgeInsets.symmetric(vertical: 16),
                    child: Center(
                      child: Text(
                        "Invalid API Key",
                        style: TextStyle(color: Colors.red),
                      ),
                    ),
                  )
                else if (_index != null) ...[
                  Container(
                    padding: const EdgeInsets.symmetric(vertical: 16),
                    child: Text(
                      "Collections",
                    ),
                  ),
                  for (var x in _index!.collections)
                    ListTile(
                        onTap: () {
                          Navigator.of(context).push(
                            MaterialPageRoute(
                              builder: (context) {
                                return CollectionView(
                                  museIndex: _index,
                                  collection: x,
                                );
                              },
                              fullscreenDialog: true,
                              maintainState: true,
                            ),
                          );
                        },
                        title: Text(x.name!),
                        trailing: x.visibility == "unlisted"
                            ? Icon(Icons.remove_red_eye_rounded)
                            : null),
                ],
              ],
            ),
          ),
        ),
      ),
    );
  }
}
0
likes
110
pub points
38%
popularity

Publisher

unverified uploader

Integrating with MUSE.ai

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

dartxx, dio, flutter, logging, pedantic

More

Packages that depend on muse_ai