simple_hashtag 0.1.0 copy "simple_hashtag: ^0.1.0" to clipboard
simple_hashtag: ^0.1.0 copied to clipboard

SimpleHashTag is a package that generates hashtags from strings.

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Simple HashTag'),
    );
  }
}

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

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  final controller = TextEditingController();
  RichText? text;

  late final SimpleHashTag _hashTag;

  @override
  void initState() {
    super.initState();
    _hashTag = SimpleHashTag();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Padding(
        padding: const EdgeInsets.all(24),
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              if (text != null) text!,
              const SizedBox(
                height: 24,
              ),
              Container(
                decoration: BoxDecoration(
                  border: Border.all(),
                  borderRadius: BorderRadius.circular(30),
                ),
                child: TextFormField(
                  controller: controller,
                  decoration: const InputDecoration(
                    isDense: true,
                    contentPadding: EdgeInsets.all(16),
                    border: InputBorder.none,
                  ),
                ),
              ),
              const SizedBox(
                height: 24,
              ),
              ElevatedButton(
                onPressed: () {
                  setState(
                    () {
                      text = _hashTag.generateHashTag(
                        controller.text,
                        (hashTag) {
                          Navigator.push(
                            context,
                            MaterialPageRoute(
                              builder: (context) => DetailPage(tag: hashTag),
                            ),
                          );
                        },
                      );
                    },
                  );
                },
                child: const Text('generate'),
              )
            ],
          ),
        ),
      ),
    );
  }

  @override
  void dispose() {
    super.dispose();
    controller.dispose();
  }
}

class DetailPage extends StatelessWidget {
  const DetailPage({
    super.key,
    required this.tag,
  });

  final String tag;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('DetailPage')),
      body: Center(
        child: Text('Moved to the $tag screen.'),
      ),
    );
  }
}
3
likes
160
points
27
downloads

Publisher

unverified uploader

Weekly Downloads

SimpleHashTag is a package that generates hashtags from strings.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on simple_hashtag