keyboard_sticky 0.2.0 copy "keyboard_sticky: ^0.2.0" to clipboard
keyboard_sticky: ^0.2.0 copied to clipboard

A UI component can sticky widget on the top of soft keyboard.

example/lib/main.dart

import 'package:example/both.dart';
import 'package:example/only_floating.dart';
import 'package:example/only_original.dart';
import 'package:example/sticky_dropdown.dart';
import 'package:example/test.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:go_router/go_router.dart';

final navigatorKey = GlobalKey<NavigatorState>();

final router = GoRouter(
  navigatorKey: navigatorKey,
  routes: [
    GoRoute(
      path: "/",
      parentNavigatorKey: navigatorKey,
      builder: (context, state) => const AttachableTextFieldExample(),
    ),
    GoRoute(
      path: "/chat",
      parentNavigatorKey: navigatorKey,
      redirect: (context, state) {
        if (state.pathParameters["partyId"] == null) {
          return "/";
        }
        return null;
      },
      routes: [
        GoRoute(
          path: ":partyId",
          parentNavigatorKey: navigatorKey,
          builder: (_, state) {
            print("Party route with partyId");
            final partyId = state.pathParameters["partyId"];
            return Material(
              child: PartyViewPage(
                partyId: partyId ?? "",
              ),
            );
          },
        ),
      ],
    )
  ],
);

void main() {
  runApp(
    const ScreenUtilInit(
      designSize: Size(428, 926),
      rebuildFactor: RebuildFactors.none,
      minTextAdapt: true,
      splitScreenMode: false,
      child: MyApp(),
    ),
  );
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      builder: EasyLoading.init(),
      routeInformationParser: router.routeInformationParser,
      routerDelegate: router.routerDelegate,
      routeInformationProvider: router.routeInformationProvider,
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      appBar: AppBar(
        title: const Text("Keyboard Sticky Example"),
      ),
      body: const Padding(
        padding: EdgeInsets.all(15),
        child: Column(
          children: [
            UnfocusButton(),
            PartyTestButton(),
            Spacer(),
            Text("Text would be sent to the floating widget"),
            SizedBox(height: 5),
            OnlyOriginalExample(),
            SizedBox(height: 20),
            Text("Text would be sent back to the original widget"),
            SizedBox(height: 5),
            OnlyFloatingExample(),
            SizedBox(height: 20),
            Text("Text sync between both fields"),
            SizedBox(height: 5),
            BothFieldsExample(),
            SizedBox(height: 20),
            StickyDropdownExample(),
            SizedBox(height: 20),
            Text("Bottom placeholder"),
          ],
        ),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return OutlinedButton(
      onPressed: () {
        context.push("/chat/party");
      },
      child: Text("Test Party"),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return OutlinedButton(
      onPressed: () {
        FocusScope.of(context).unfocus();
      },
      child: const Text("Unfocus"),
    );
  }
}
0
likes
160
pub points
47%
popularity

Publisher

verified publishersimonwang.dev

A UI component can sticky widget on the top of soft keyboard.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on keyboard_sticky